What is the meaning of ArrayController in Ember.js?

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

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

Here's how the ArrayController used:

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

How will this work otherwise than using a simple array instead?

 MyApp.listController = []; $.get('people.json', function(data) { MyApp.set('listController', data); }); 
+7
source share
2 answers

If you do not need controller behavior, you can use a simple array.

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

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

+5
source

ember.js documentation says:

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

The advantage of using ArrayController is that you only need to set at the same time bind your bindings to the view; change the displayed, just replace the outside content property on the controller.

it uses an array in the background, helps only with methods of working with an array:

Although you are attached to the controller, the behavior of this controller should pass any methods or properties to the main array

+5
source

All Articles