最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What's the point of ArrayController in Ember.js? - Stack Overflow

programmeradmin2浏览0评论

The documentation has an example of using an ArrayController with this template:

{{#each MyApp.listController}}
  {{firstName}} {{lastName}}
{{/each}}

This is how the ArrayController is used:

MyApp.listController = Ember.ArrayController.create();

$.get('people.json', function(data) {
  MyApp.listController.set('content', data);
});

How would this work differently than using a plain array like this instead?

MyApp.listController = [];

$.get('people.json', function(data) {
  MyApp.set('listController', data);
});

The documentation has an example of using an ArrayController with this template:

{{#each MyApp.listController}}
  {{firstName}} {{lastName}}
{{/each}}

This is how the ArrayController is used:

MyApp.listController = Ember.ArrayController.create();

$.get('people.json', function(data) {
  MyApp.listController.set('content', data);
});

How would this work differently than using a plain array like this instead?

MyApp.listController = [];

$.get('people.json', function(data) {
  MyApp.set('listController', data);
});
Share Improve this question asked Jul 3, 2012 at 18:20 nicholaidesnicholaides 19.5k13 gold badges70 silver badges83 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

If you don't need the behavior of a controller, you can use a plain array.

An ArrayController wraps an array, with some other properties added, such as the sortable mixin. You can see it here:

https://github./emberjs/ember.js/blob/master/packages/ember-runtime/lib/controllers/array_controller.js

in the ember.js documentation says:

(http://docs.emberjs./symbols/Ember.ArrayController.html)

The advantage of using an ArrayController is that you only have to set up your view bindings once; to change what's displayed, simply swap out the content property on the controller.

it uses an Array in background, only helps with methods to work with the array:

Although you are binding to the controller, the behavior of this controller is to pass through any methods or properties to the underlying array

发布评论

评论列表(0)

  1. 暂无评论