如何通过点击事件传递值Ember Js控制器

时间:2014-11-24 07:17:47

标签: javascript jquery ember.js

** strong text **如何在ember中传递值控制器

<div>
{{view  "select"  content=model    prompt="Please select a name"  selectionBinding="App.selectedComboBoxController.model"  optionValuePath="content.fullName" optionLabelPath="content.title"  }}

    </div>

    -
    <p>
        Selected: {{App.selectedComboBoxController.model.title}}
</p>

在代码上方我得到正确的输出。 但我希望将该值传递给控制器​​而不需要任何按钮

**Here my controller.**

App.ComboBoxController = Ember.Controller.extend({

});

1 个答案:

答案 0 :(得分:0)

需要将保存所选值的控制器与当前上下文相关联。因此,在下面的示例中,假设当前上下文是索引路由,模型返回一个对象数组。

示例

<强> HBS

<script type="text/x-handlebars" data-template-name="index">
  <div>
   {{view  "select"  content=model    prompt="Please select a name"  selectionBinding="controllers.selectedComboBox.model"  optionValuePath="content.fullName" optionLabelPath="content.title"  }}
</div>

    -

    <p>
        Selected: {{controllers.selectedComboBox.model.title}}
</p>
  </script>

<强> JS

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return [
      {fullName:"the full name1", title:"the title1"},
      {fullName:"the full name2", title:"the title2"},
      {fullName:"the full name3", title:"the title3"}
    ];
  }
});

App.IndexController = Em.ArrayController.extend({
  needs:["selectedComboBox"]

});

App.SelectedComboBoxController = Em.ObjectController.extend({
  model:null
});

http://emberjs.jsbin.com/jodaqumoba