如何将绑定模型传递给输入操作方法

时间:2014-02-10 16:15:05

标签: ember.js

我的车把模板里面有一个输入

{{#each thing in controller}}
  {{input action="update_model" class="blue"}}
{{/each}}

这将正确截取“输入密钥”,但我需要将我的“事物”模型传递给更新操作,如何使用最新版本的ember.js执行此操作?

actions: {
  update_model: function(model) {
    //do something w/ the model even when the user hits enter
  }
}

1 个答案:

答案 0 :(得分:1)

这可能不是最优雅的解决方案,但这应该有效:

{{#each thing in controller}}
  {{view App.CustomView class="blue" action="update_model" controller=controller param=thing }}
{{/each}}

App.CustomView = Ember.TextField.extend({
  keyPress:function(e) {
    if (e.keyCode == 13) {
      this.get("controller").send(this.get("action"), this.get("param"))
    }
  }
})