【问题标题】:How do I set the value of a property in Controller A from within Controller B?如何从控制器 B 中设置控制器 A 中的属性值?
【发布时间】:2013-10-07 17:27:25
【问题描述】:

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

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

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

【问题讨论】:

    标签: javascript ember.js ember-data javascript-framework


    【解决方案1】:

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

    NerfController = Ember.Controller.extend({
        needs: ['other'],
    
        setValueInOther: function(newValue) {
            this.get('controllers.other').set('value', newValue);
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2015-02-10
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-22
      相关资源
      最近更新 更多