Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the point of ArrayController in Ember.js?

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);
});
like image 314
nicholaides Avatar asked Jul 03 '12 18:07

nicholaides


People also ask

What are controllers in Ember JS?

In Ember. js, controllers allow you to decorate your models with display logic. In general, your models will have properties that are saved to the server, while controllers will have properties that your app does not need to save to the server.

Is ember still used?

Ember has been an enabler of great productivity for many teams for almost a decade and I'm sure it's going to continue to be that. It's changed and improved a lot since its first release and is now in better shape than ever with its Octane edition.

Is Ember front end?

EmberJS is one of the most opinionated front-end frameworks out there.


2 Answers

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.com/emberjs/ember.js/blob/master/packages/ember-runtime/lib/controllers/array_controller.js

like image 95
sly7_7 Avatar answered Oct 21 '22 08:10

sly7_7


in the ember.js documentation says:

(http://docs.emberjs.com/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

like image 30
Pablo Martinez Avatar answered Oct 21 '22 07:10

Pablo Martinez