I have two controllers: controller A and controller B. Controller A has a property called "total_price" which has a numeric value. I'd like to set the "total_price" value of Controller A to 0, from within controller B.

I know needs (http://emberjs.com/guides/controllers/dependencies-between-controllers/) lets you access other controller properties but I can't see anything in the documentation about setting another controller's properties.

How can I accomplish this? Thanks!

有帮助吗?

解决方案

If you use the needs api to get controller A, you can set values on that controller like you normally would.

NerfController = Ember.Controller.extend({
    needs: ['other'],

    setValueInOther: function(newValue) {
        this.get('controllers.other').set('value', newValue);
    }
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top