我正在尝试向kendoDropDownList添加一个项目,它似乎添加了该选项但未设置值和文本。检查选择它只是添加一个新选项
<option></option>
以下是我正在使用的内容
$("#nameList").data("kendoDropDownList")
.dataSource.add({ "text": "Joe", "value": "Joe" });
更新
这是我的数据源模型和建议的requestEnd
,但值似乎搞砸了
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.plaintiffs;
},
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"});
}
}
});
答案 0 :(得分:8)
经过一番搜索,这很简单,但这正是我所需要的。
$("#people_list").getKendoDropDownList().dataSource.insert({
person_id: "John",
name: "John"
})
答案 1 :(得分:3)
您可以使用requestEnd加载新项目到数据源。
requestEnd: function (e) {
e.response.push({text: "Joe", value: "Joe"});
}
我已经更新了其他用户的小提示,以向您展示它的有效性。 jsFiddle example
答案 2 :(得分:1)
使用此:
<input id="nameList" value="1" />
var data = [
{ text: "Joe", value: "Joe" },
{ text: "Joe", value: "Joe" },
{ text: "Joe", value: "Joe" }
];
// create DropDownList from input HTML element
$("#nameList").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
dataSource: data,
index: 0,
});
答案 3 :(得分:0)
不确定您想要什么,但您可以从数据源加载选项,然后在dataBound
触发后将更多内容附加到列表中。
$("#nameList").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
dataSource: {
transport: {
read: {
dataType: 'json',
type: 'GET',
url: '/restful/companies'
}
}
},
dataBound:onDataBound
});
<script>
function onDataBound(e) {
e.sender.dataSource.add({ "text": "Joe", "value": "Joe" });
}
</script>