【发布时间】:2015-05-13 17:16:07
【问题描述】:
我有一个通过 data- 属性初始化的 DropDownList。我需要向列表中添加一个项目,但在我推送新选项后,我使用的代码将值显示为“未定义”。
这是我使用 data- 属性的元素(工作正常):
<select id="#people_list"
name="person_id"
class="form-control"
data-role="dropdownlist"
data-source="datasource_people"
data-option-label="Select A Name"
data-auto-bind="true"
data-text-field="name"
data-value-Field="name"
data-ignore-case="true"
data-filter="startswith"
>
</select>
这是我的数据源参数(工作正常):
datasource_people = new kendo.data.DataSource({
type: "json",
serverFiltering: true,
transport: {
read: {
dataType: 'json',
type: 'GET',
url: '/restful/people/'
}
},
filter: {
field: "status",
operator: "eq",
value: 1
},
schema: {
data: function(response) {
return response.data.people;
},
model: {
id: "person_id",
fields: {
person_id: {type: "number"},
name: { type: "string"}
}
},
errors: "error",
total: function(response) {
return response.data.total;
}
}
});
然后稍后(不起作用 - 将新项目添加为“未定义”):
$("#people_list").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
dataSource: {
datasource_people,
requestEnd: function (e) {
e.response.push({text: "John", value: "John"});
}
}
});
【问题讨论】:
-
可能是dataTextField和dataValueField不对?
标签: jquery kendo-ui kendo-dropdown