问题描述
我具有来自Web服务查询(_urlTowns)的以下json数据(请参见下文).我想将Kendo UI下拉列表控件绑定到此datasourceTowns.
I have the following json data (see below) from a webservice query (_urlTowns). I want to bind a Kendo UI dropdownlist control to this datasourceTowns.
{
"displayFieldName": "TNONAM",
"fieldAliases": {
"TNONAM": "TNONAM"
},
"fields": [{
"name": "TNONAM",
"type": "esriFieldTypeString",
"alias": "TNONAM",
"length": 16
}],
"features": [{
"attributes": {
"TNONAM": "ANSONIA"
}
}, {
"attributes": {
"TNONAM": "BETHANY"
}
}, {
"attributes": {
"TNONAM": "BRANFORD"
}
}, {
"attributes": {
"TNONAM": "WOODBRIDGE"
}
}]}
// Towns data source
var dataSourceTowns = new kendo.data.DataSource({
transport: {
read: {
url: _urlTowns,
dataType: "json",
type: 'GET'
}
},
schema: {
data: "features"
}});dataSourceTowns.read();
我需要设置模型属性吗?正如我在用来自"TNONAM"的dataTextValue填充DDL之后一样.猜猜我混淆了功能"和属性".
Do I need to set a model attribute? As I'm after populating the DDL with the dataTextValue from "TNONAM". Guess I'm confusing the "features" and "attributes".
推荐答案
也许您的JSON对于DropDownList而言不是最方便,但您可以将其绑定到KendoDropDownList而无需更改.
Maybe your JSON is not the most convenient for a DropDownList but you can bind it to a KendoDropDownList with no change.
将DropDownList定义为:
Define the DropDownList as:
$("#dropdown").kendoDropDownList({
dataSource : dataSourceTowns,
dataTextField : "attributes.TNONAM"
});
请记住,dataTextField
不一定非要是一个字段,可以是该字段的路径.
Remember that dataTextField
doesn't strictly have to be a field, might be path to the field.
HTML所在的位置:
Where your HTML is:
<select id="dropdown"></select>
这篇关于将json正确绑定到Kendo DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!