3
votes

I have an ArrayController which manages a group of objects. I define an itemController on this, so that each individual object is managed by another ObjectController:

App.IndexController = Ember.ArrayController.extend({
  itemController: "sampleModel"
});

Inside this ObjectController, I have a delete action that is meant to delete objects from the enclosing array, using the "parent" ArrayController:

App.SampleModelController = Ember.ObjectController.extend({
  delete: function() {
    this.get("target.content").removeObject(this.get("content"));
  }
});

I don't want to have a global object store. I'm currently using the target property in order to achieve this kind of behaviour. Is this the idiomatic ember approach?

The complete example can be found here.

1

1 Answers

6
votes

You can move the delete function to the ArrayController. This way makes sense because the array controller is managing the collection. The way you have it works, but it doesn't seem right because your object is managing the array that it belongs to, which just seems like an awkward way of writing it.

App.IndexController = Ember.ArrayController.extend({
  itemController: "sampleModel",

  delete: function(object) {
    this.get('content').removeObject(object)
  }
});

App.SampleModelController = Ember.ObjectController.extend({});

jsfiddle