admin管理员组文章数量:1356873
In ember's official guide, it provides two ways to set the controller's underlying object. First is setting the model property:
App.SongsRoute = Ember.Route.extend({
setupController: function(controller, playlist) {
controller.set('model', playlist.get('songs'));
}
});
Second is setting the content property:
MyApp.listController = Ember.ArrayController.create();
$.get('people.json', function(data) {
MyApp.listController.set('content', data);
});
Are these two properties represent the same thing? Which way should i use?
In ember's official guide, it provides two ways to set the controller's underlying object. First is setting the model property:
App.SongsRoute = Ember.Route.extend({
setupController: function(controller, playlist) {
controller.set('model', playlist.get('songs'));
}
});
Second is setting the content property:
MyApp.listController = Ember.ArrayController.create();
$.get('people.json', function(data) {
MyApp.listController.set('content', data);
});
Are these two properties represent the same thing? Which way should i use?
Share Improve this question asked Jan 9, 2014 at 11:17 merlinmerlin 341 gold badge15 silver badges23 bronze badges2 Answers
Reset to default 7It seems they are the same thing,
https://github./emberjs/ember.js/blob/v1.3.0/packages/ember-runtime/lib/controllers/controller.js#L44
Ember.ControllerMixin = Ember.Mixin.create(Ember.ActionHandler, {
....
model: Ember.puted.alias('content'),
....
The model
property is an alias for content
.
Also,
https://github./emberjs/ember.js/blob/v1.3.0/packages/ember-routing/lib/system/route.js#L849
which mentions that,
By default, the `setupController` hook sets the `content` property of the controller to the `model`.
UPDATE Deprecated since v1.7.0 and the code placed in a mixin. https://github./emberjs/ember.js/blob/v2.12.0/packages/ember-runtime/lib/mixins/controller.js Along with the related deprecation mixin. https://github./emberjs/ember.js/blob/v2.12.0/packages/ember-runtime/lib/mixins/controller_content_model_alias_deprecation.js
In the documentation - http://emberjs./api/classes/Ember.Controller.html#property_model - it clearly states that when retrieving or modifying a controller's model, the model property should be used instead of the content property.
本文标签: javascriptEmberWhat39s the difference between controller39s content and model propertyStack Overflow
版权声明:本文标题:javascript - Ember - What's the difference between controller's content and model property - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743969095a2570432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论