Search code examples
ember.jscontrollerenumerableember-old-router

Find item in Ember ArrayController


What's the proper way to find item in the Ember.js ArrayController? I have set of contacts in the controller:

App.contactsController = Em.ArrayController.create({
    content:[],
});

There are objects in the controller, they are displayed and everything works fine. Then, I want to implement router with serialization/deserialization:

...
deserialize:function (router, params) {
    var contact = App.contactsController.find(function(item) {
        return item.id == params.contact_id;
    });
},
...

However, the find function does not appear to do any iteration. What could be the reason? Is it possible that the Router tries to do the routing before the application calls its ready method? That's the place I fill the controller with data.

EDIT: Well, I have found that router tries to make the transition before I fill my arrayController by the data (in Ember.Application.ready method). Is it possible to "delay" routing after the data is properly set?


Solution

  • The problem was actually caused by insertind data into arrayController after the Router did its deserialization. Putting it before App.initialize() solved the problem.