0
votes

I need to know how to get an ArrayController's position of an object in it's content array. Let's say:

App.AnArrayController = Ember.ArrayController.set({
   content: [],
});

App.AnObject = Ember.Object.set({
   name: null,
   lastname: null,
   id: 0
});

Now, let's say that i've inserted two AnObject in AnArrayController's content. How can I update a particular object's value without knowing it's position in the ArrayController, but knowing just that the object's id property is X?

Thanks!

1

1 Answers

1
votes

First: Why are you using the set methods? I would expect your code snippet to be (you need to define your classes first via extend()):

 App.AnArrayController = Ember.ArrayController.extend({
     content: [],
 }); 

App.AnObject = Ember.Object.extend({
   name: null,
   lastname: null,
   id: 0
});

If the id is unique you can use the filterProperty. After calling App.initialize(), you can access your controller with the helpt of the router via:

var controller = App.router.get("anArrayController");
anObject = controller.findProperty("id", 1); //find Object with id 1
// do something with anObject