Ember.js 余烬余烬。选择“获取选定值”
我有一个简单的余烬应用程序,其中有一个输入框、两个选择框和一个按钮。我可以访问方法“doSearch”中输入框的值,但不能访问选择框的值。 到目前为止,我尝试的都没有成功——我对访问选择的失败尝试进行了注释。我开始认为这与我对余烬有限的知识有关 任何帮助都将不胜感激。 这是我的HTML和脚本:Ember.js 余烬余烬。选择“获取选定值”,ember.js,Ember.js,我有一个简单的余烬应用程序,其中有一个输入框、两个选择框和一个按钮。我可以访问方法“doSearch”中输入框的值,但不能访问选择框的值。 到目前为止,我尝试的都没有成功——我对访问选择的失败尝试进行了注释。我开始认为这与我对余烬有限的知识有关 任何帮助都将不胜感激。 这是我的HTML和脚本: <script type="text/x-handlebars" data-template-name="application"> <div id="heade
<script type="text/x-handlebars" data-template-name="application">
<div id="headerDiv">
<ul>
<li>
<image src="logo.png" style="width:439px;height:102px;"/>
</li>
<li>
{{input type="text" placeholder="Search content" value=newSearch action="doSearch"}}
</li>
<li>
<button type="button" {{action "doSearch"}}>Search</button>
</li>
<li>{{#link-to 'home'}}Home{{/link-to}} | {{#link-to 'help'}}Help{{/link-to}}</li>
</ul>
</div>
<span class="filter">Content Type:
{{view Ember.Select
content=selectContentType
optionValuePath="content.value"
optionLabelPath="content.label"}}
</span>
<span class="filter">Date:
{{view Ember.Select
content=selectDate
optionValuePath="content.value"
optionLabelPath="content.label"}}
</span>
</script>
使用两个新变量扩展
应用程序控制器
,以保存所选值:
App.ApplicationController = Ember.ArrayController.extend({
selectedContentType: null,
selectedDate: null,
...
});
并使用类的selectionBinding
属性绑定到这些变量
<span class="filter">Content Type:
{{view Ember.Select
content=selectContentType
optionValuePath="content.value"
optionLabelPath="content.label"
selectionBinding=selectedContentType}}
</span>
<span class="filter">Date:
{{view Ember.Select
content=selectDate
optionValuePath="content.value"
optionLabelPath="content.label"
selectionBinding=selectedDate}}
</span>
希望有帮助。太棒了!你是我的天使。非常感谢你-它像一个符咒一样工作。我正在使用金丝雀构建(用于queryParams!),但这不起作用。我认为它应该是值,而不是selectionBinding。是的,它对我有用。“selectionBinding”在我的观点中我错过了。感谢您再次使用余烬。在余烬2.0中不推荐使用Select global:
<span class="filter">Content Type:
{{view Ember.Select
content=selectContentType
optionValuePath="content.value"
optionLabelPath="content.label"
selectionBinding=selectedContentType}}
</span>
<span class="filter">Date:
{{view Ember.Select
content=selectDate
optionValuePath="content.value"
optionLabelPath="content.label"
selectionBinding=selectedDate}}
</span>
App.ApplicationController = Ember.ArrayController.extend({
selectedContentType: null,
selectedDate: null,
...
actions: {
doSearch: function () {
var selectedDate = this.get('selectedDate.value');
console.log( selectedDate );
var selectedType = this.get('selectedContentType.value');
console.log( selectedType );
}
}
});