jQuery 如何检索剑道ui下拉列表的所有数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19250972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to retrieve all data of a kendo ui dropdown list?
提问by kparkin
I want to pull all data of a kendo dropdown list. I create dropdown with this code:
我想提取剑道下拉列表的所有数据。我使用以下代码创建下拉列表:
$("#dropDownList").kendoDropDownList({
dataTextField: "field",
autoBind: true,
dataSource: {
transport: {
type: "POST",
read: {
url: "http://abc.com",
contentType: "application/json; charset=utf-8",
dataType: "json"
}
}
},
select: onSelect
});
};
};
Then I tried to pull data with using
然后我尝试使用以下方法提取数据
var data = $("#dropDownList").data("kendoDropDownList").val();
var values = [];
for (var item in data) {
values.push(this.item);
}
But it didn't work. Any idea how can I do? Thanks in advance.
但它没有用。知道我该怎么做吗?提前致谢。
回答by Vijai
Try this it will retrive all values from Kendo dropdown.
试试这个,它将从 Kendo 下拉列表中检索所有值。
var values = [];
var grid = $("#SampleDropdown").data("kendoDropDownList");
var ds = grid.dataSource;
var len = ds._data.length;
if (len > 0) {
var i;
for (i = 0; i < len; i++) {
var val = ds._data[i].Value;
values.push(val);
}
}
回答by BENARD Patrick
Can you try :
你能试一下吗 :
var data = $("#dropDownList").data("kendoDropDownList");
回答by BGTurner
If you want the actual DataItems from the DDL you can get them by Viewing the DataSource:
如果您想要来自 DDL 的实际数据项,您可以通过查看数据源来获取它们:
$("#dropDownList").data("kendoDropDownList").dataSource.view()
You can then also find individual items easily by id if you need to:
如果您需要,您还可以通过 id 轻松找到单个项目:
$("#dropDownList").data("kendoDropDownList").dataSource.view().find(x=>x.Value === 'ID')
回答by sudhAnsu63
Try this.
尝试这个。
var values = [];
var data = $("#dropDownList option").each(function(){
values.push($(this).val());
});
回答by shaijut
回答by Andriy Leshchuk
$("#dropDownList").data('kendoDropDownList').options.optionList
- returns object with values
$("#dropDownList").data('kendoDropDownList').options.optionList
- 返回带有值的对象