Ember.js中ArrayController的重点是什么?

nic*_*des 7 javascript model-view-controller ember.js

该文档有一个使用ArrayController此模板的示例:

{{#each MyApp.listController}}
  {{firstName}} {{lastName}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)

这是如何ArrayController使用:

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

$.get('people.json', function(data) {
  MyApp.listController.set('content', data);
});
Run Code Online (Sandbox Code Playgroud)

这比使用像这样的普通数组有何不同?

MyApp.listController = [];

$.get('people.json', function(data) {
  MyApp.set('listController', data);
});
Run Code Online (Sandbox Code Playgroud)

sly*_*7_7 5

如果您不需要控制器的行为,则可以使用普通数组.

ArrayController包装一个数组,并添加了一些其他属性,例如可排序的mixin.你可以在这里看到它:

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


Pab*_*nez 5

在ember.js文档中说:

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

使用ArrayController的优点是你只需要设置一次视图绑定; 要更改显示的内容,只需在控制器上交换内容属性即可.

它在后台使用一个数组,只对使用数组的方法有所帮助:

虽然您绑定到控制器,但此控制器的行为是将任何方法或属性传递给基础数组