sách gpt4 ai đã đi

ember.js - Ember Ember.select 获取选定值

In lại 作者:行者123 更新时间:2023-12-04 23:52:50 31 4
mua khóa gpt4 Nike

我有一个简单的 Ember 应用程序,其中有一个输入框、两个选择框和一个按钮。我可以在“doSearch”方法中访问输入框的值,但不能访问选择框的值。
到目前为止,我没有尝试任何工作 - 我注释掉了我访问选择的失败尝试。我开始认为这与我对 Ember 的有限知识有关。

任何帮助都感激不尽。
这是我的 HTML 和脚本:

    

这是我试图到达选择框的 javascript:
App = Ember.Application.create();

App.Router.map(function(){
this.resource('home', { path: '/' });
this.resource('help');
});

App.ApplicationController = Ember.ArrayController.extend({
selectContentType: [
{label: "All", value: "all"},
{label: "Text", value: "text"},
{label: "Image", value: "image"}
],
selectDate: [
{label: "None", value: "none"},
{label: "Today", value: "today"},
{label: "Last 7 days", value: "7days"}
],
actions: {
doSearch: function () {
var searchVal = this.get('newSearch');
if (!searchVal.trim()) {return;}
console.log('got searchVal: ',searchVal );

var selectType = $("#selectContentType").val();
//$("#selectContentType option:selected").val();
//this.get('selectContentType.value');
console.log('got selectType: ',selectType );
}
}
});

1 Câu trả lời

扩展您的ApplicationController有两个新变量来保存选定的值:

App.ApplicationController = Ember.ArrayController.extend({
selectedContentType: null,
selectedDate: null,
...
});

và sử dụng selectionBinding Ember.Select 的属性(property)绑定(bind)到这些变量的类
Content Type:
{{view Ember.Select
content=selectContentType
optionValuePath="content.value"
optionLabelPath="content.label"
selectionBinding=selectedContentType}}

Date:
{{view Ember.Select
content=selectDate
optionValuePath="content.value"
optionLabelPath="content.label"
selectionBinding=selectedDate}}


然后您可以稍后通过以下方式轻松访问它们:
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 );
}
}
});

希望能帮助到你。

关于ember.js - Ember Ember.select 获取选定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19818420/

31 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com