Why is "this" so complicated? Calling Controller "method"


#1

I have a ObjectController with that creates a TREE like structure based on a model (list of EmberData objects) - with a property that observers the model “length” - when the length changes.

When objects get added I need to recreate the tree - but I can not call treeContent

The Ember.run.once function does not call treeContent and can not see it …“this” is not the controller !!

var ScenGrpsController = Ember.ObjectController.extend({ modelDidChange: function(e) { var _self=this; Ember.run.once(_self, “treeContent”); }.observes(‘model.length’),

treeContent: function() {}

I know “this” is a pain but how can I get a ref to the controller I am in ?


#2

Reproduce it with a jsfiddle so we can more easily respond with a solution.


#3
var ScenGrpsController = Ember.ArrayController.extend({
   treeContent: function() {
    // do the tree stuff here
  }.observes('model.[]')

Just do that. That should do it!


#4

Thank you - that solves 1 problem!