3

Is there any way to get a hand on the model from a controller? I would need to call an instance method defined on the model and

this.get(methodName)(params)

does not work, as it loses the 'this' call context within the called function.

Thank you.

Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
Tudor Vintilescu
  • 1,450
  • 2
  • 16
  • 28

1 Answers1

1

I'm not sure which context you want to exist in the method, if you need to switch the context you can use call/apply. The context should be the context of the method, not the controller by javascript standards.

var model = this.get('model');

model.methodName(arg1, arg2);

Controller's context

model.methodName.apply(this, arrayOfArgs);

model.methodName.call(this, arg1, arg2);
Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
  • Thanks, man! This question was really stupid, had tried calling this.get('model') but was in a jQuery handler by accident and the 'this' was pointing to something different, hence the strive to do this.get('methodName')(params) – Tudor Vintilescu Jun 20 '14 at 12:16
  • And another big thank you for repetedly helping me with my Ember journey. You seem to be one of the few active Ember guys around SO. – Tudor Vintilescu Jun 20 '14 at 12:19