Ember link-to model. , :
{{#each book in model}}
{{#link-to 'book' book}}{{book.name}}{{/link-to}}
{{/each}}
, , , BookRoute . BookController#init . , .
App.BookController = Ember.Controller.extend({
init: function() {
this._super();
if (doesNotHaveAllInfo) {
this.set('model', Ember.$.getJSON('/book?id=' + this.get('model.id') + '&version=' + this.get('model.version')));
}
},
});
, link-to, . , , , index, id version.
, , model, doesNotHaveAllInfo false. link-to , .
I would also recommend abstracting the code Ember.$.getJSONinto a reusable method, perhaps on a model, for example:
App.Book.reopenClass({
find: function(id, version) {
return Ember.$.getJSON('/book?id=' + id + '&version=' + version);
}
});
Then you can use App.Book.find()to return your model both on your route and on yours BookController.
source
share