javascript - Ember Nested Route and Promises -
i have jquery ajax call defined this
var fetchmessages = function(){$.getjson(<some url>).then(function(data){ return data; }}; var messages = fecthmessages();
my routes setup this
app.router.map(function() { this.resource('messages', function() { this.resource('message', { path: ':message_id' }); }); });
i use promise messages
in routes this
app.messagesroute = ember.route.extend({ model : function(){ return messages; } });
the above route works fine.
next have nested route shown below. errors out when directly try visit #/messages/<id of message>
. loading #/messages
followed visiting #/messages/<id of message>
works fine.
app.messageroute = ember.route.extend({ model: function(params) { message = messages.findby("id", params.message_id); return message; } });
so how handle promises in nested routes?
so how handle promises in nested routes?
apparently ember handles these you.
this errors out when directly try visit #/messages/:
app.messageroute = ember.route.extend({ model: function(params) { message = messages.findby("id", params.message_id); return message; } });
messages
still promise, not array; doesn't have findby
method. instead, use
return messsages.then(function(m) { return m.findby("id", params.message_id); });
Comments
Post a Comment