** 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({
});
答案 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
});