0

我有两个控制器:控制器 A 和控制器 B。控制器 A 有一个名为“total_price”的属性,它有一个数值。我想在控制器 B 中将控制器 A 的“total_price”值设置为 0。

我知道需要(http://emberjs.com/guides/controllers/dependencies-between-controllers/)可以让您访问其他控制器属性,但我在文档中看不到有关设置另一个控制器属性的任何内容。

我怎样才能做到这一点?谢谢!

4

1 回答 1

1

如果您使用需求 api 来获取控制器 A,您可以像往常一样在该控制器上设置值。

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

    setValueInOther: function(newValue) {
        this.get('controllers.other').set('value', newValue);
    }
});
于 2013-10-01T14:04:22.693 回答