如何使用远程数据将选择下拉到我的一个Kendo ui网格列中?
关于这个主题的文档非常有限,特别是我的要求是:
要从我的PHP / MySQL脚本中获取选项列表,请填充下拉菜单 .
如果已根据数据库中的查询设置了其中一个选项,则已在菜单中选择该选项 .
根据提供的答案,我现在有以下内容,但它不起作用 . 我得到一个下拉列表,其中包含所有“未定义”的选项:
function categoryDropDownEditor(container, options) {
$('<input required data-text-field="'+options.field+'" data-value-field="'+options.field+'" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataTextField: "text",
dataValueField: "value",
dataSource: {
type: "POST",
transport: {
read: ROOT+"user/branch-list"
}
},
index: 0
});
}
我的PHP脚本只返回JSON,如下所示:
[{text: "Germany", value: "1"}]
2 回答
定义该字段的列时,可以使用editor .
其中
editColor
是一个定义为的函数:您可以在
kendoDropDownList
中设置所需的configuration option .您还可以检查数据源是否正确解析数据 .
例如,我的json看起来像你可以看到实际记录包含在_ENTITIES数组中 . 因此,为了使数据源正确解析,我必须在我的数据源的模式中指定数据:“_ ENTITIES” . 我希望这有帮助
schema:{model:myModel,data:“__ ENTITIES”}
{“_entityModel ":"联系"," _COUNT ":13," _SENT ":13," _First ":0," _ENTITIES ":[{" _key ":" 177 "," _STAMP ":16," ID ":177,"的firstName ":" ","中间名":" "," lastName的":" "," ContactType ":{" _key ":" 2 "," _STAMP ":4," ID ":2,"名":"首页"," contactCollection ":{" _deferred ":{" URI ":" / rest / ContactType(2)/ contactCollection?$ expand = contactCollection "}}}," addressCollection ":{" __deferred ":{" uri ":" / rest / Contact(177)/ addressCollection?$ expand = addressCollection“}}},
{“_key ":" 180 "," _STAMP ":5," ID ":180,"的firstName ":"一个","中间名":" b "," lastName的":"Ç"," ContactType ":{" _key ":" 2 "," _STAMP ":4," ID ":2,"名称":"主页"," contactCollection ":{" _deferred ":{" URI ":" /休息/ ContactType(2)/ contactCollection?$ expand = contactCollection "}}}," addressCollection ":{" _deferred ":{" uri ":" / rest / Contact(180)/ addressCollection?$ expand = addressCollection“}}}