C# 将数据绑定到剑道下拉列表时,如何将ajax响应数据绑定到变量?
我正在使用剑道下拉框来显示我的网页。这是我的java脚本函数C# 将数据绑定到剑道下拉列表时,如何将ajax响应数据绑定到变量?,c#,javascript,ajax,json,kendo-ui,C#,Javascript,Ajax,Json,Kendo Ui,我正在使用剑道下拉框来显示我的网页。这是我的java脚本函数 function BindNonEventDownList(_propertyId, _url, _textField, _valueField) { $(_propertyId).kendoDropDownList({ optionLabel: '<%= Resources.ResourceiChain.Select %>',
function BindNonEventDownList(_propertyId, _url, _textField, _valueField) {
$(_propertyId).kendoDropDownList({
optionLabel: '<%= Resources.ResourceiChain.Select %>',
dataTextField: _textField,
dataValueField: _valueField,
dataSource: {
type: "json",
serverFiltering: true,
transport: {
read: _url
},
schema: {
data: "Data",
total: "Count"
}
}
});
}
我想把这个计数变成一个变量。我该怎么做?您可以使用数据源的方法:
var dropdown = $(_propertyId).data("kendoDropDownList");
var count = dropdown.dataSource.total();
但是,请确保在调用total方法时已收到数据。否则它将返回0。我找到了答案……首先初始化了数据源。然后使用data.length可以得到数据的长度
function BindNonEventDownList(_propertyId, _url, _textField, _valueField) {
var dataSource = new kendo.data.DataSource({
transport: {
read: _url
},
schema: {
data: "Data",
total: "Count"
}
});
dataSource.fetch(function(){
var data = this.data();
console.log("data:"+data.length);
});
$(_propertyId).kendoDropDownList({
optionLabel: '<%= Resources.ResourceiChain.Select %>',
dataTextField: _textField,
dataValueField: _valueField,
dataSource: dataSource
});
}
我想在这个函数BindNonEventDownList\u propertyId、\u url、\u textField、\u valueField{}中获取计数,但你不能。您需要接收服务器响应。
function BindNonEventDownList(_propertyId, _url, _textField, _valueField) {
var dataSource = new kendo.data.DataSource({
transport: {
read: _url
},
schema: {
data: "Data",
total: "Count"
}
});
dataSource.fetch(function(){
var data = this.data();
console.log("data:"+data.length);
});
$(_propertyId).kendoDropDownList({
optionLabel: '<%= Resources.ResourceiChain.Select %>',
dataTextField: _textField,
dataValueField: _valueField,
dataSource: dataSource
});
}