javascript - Emberjs a good way to handle async ajax calls -


i quite new emberjs , know best way deal following:

view:

{{#if model}}   <p>i exist</p> {{else}}   <p>login first</p> {{#if}} 

in js:

app = em.application.create({});  app.myroute = em.route.extend({   setupcontroller: function(){     $.get("some/ajax/call",function(data){         controller.set('model', data)});     }   } }}; 

in above example setupcontroller complete , flashes <p>login first</p> , when data arrive form ajax call changes <p>i exist</p> try in model result same.

currently use jquery hide , unhide stuff around don't think best way? seems abit brittle me. advice helpful

thanks

you can use aftermodel hook perform checks. hook fires model returned jquery, before setupcontroller.

model: function() {   return $.get("some/ajax/call",function(data){       return data;   } },  aftermodel: function(model) {   // if model not valid    // transitionto route etc } 

note return data jquery promise. ember understands when promise resolved value model.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -