如何更新其他控制器的属性并更新其值?

时间:2013-09-02 21:20:43

标签: ember.js

我创建了以下示例代码:

http://ninjy.com:8080/ember/How%20to%20set%20a%20lower%20controller%27s%20variables/#/blah

单击按钮时,应该更改模板化文本。它确实这样做,但更改不会在屏幕上更新。当你交换值和动作时,它可以正常工作:当按钮位于Blah(行下方)和Application中的模板值(行上方)时,该值会在屏幕上成功更新。

有人可以解释为什么会这样发生,以及如何正确更新价值?

1 个答案:

答案 0 :(得分:1)

您需要提供小写的名称,例如需要控制器时blah代替Blah

App.ApplicationController = Ember.ObjectController.extend({
  needs: ['blah'],
  act: function() {
    console.log('act');
    var ctrl = this.get('controllers.blah');
    ctrl.set('myvalue', 'and this is the replacement text');
  }
});

Working jsbin.

希望它有所帮助。