我有一个剑道下拉列表及其工作,我只是想知道我是否可以弹出一个消息,或者当kendodropdown显示零数据时显示...我可以使用jquery吗? ??
继承我的代码
<input id="ddlWorker" name="Worker" class:"validate[required] inputLong" style="width: 400px;" value="@workerPosId" required />
$("#ddlWorker").kendoDropDownList({
dataTextField: "workerName",
dataValueField: "workerID",
autoBind: false,
optionLabel: {
workerName: "--- Please Assign A Worker ---",
workerID: ""
},
// define custom template
template:
'<h5>${ data.workerName }</h5>' +
'#if(data.AvailableDay_LookID) {#<p>${ data.AvailableDay_LookID }</p>#}#' +
'#if(data.StartTime && data.EndTime) {#<p>${ data.StartTime } - ${ data.EndTime }</p>#}#',
dataSource: {
transport: {
read: {
url: '/Client/LoadWorkerDropdownList?clientCusPosShiftId=' + clientCusPosShiftId,
dataType: "json",
type: "POST"
}
}
}
});
感谢。
答案 0 :(得分:1)
你可以试试这个。
使用var对象存储json数据。
var xhReq = new XMLHttpRequest();
xhReq.open("POST", '/Client/LoadWorkerDropdownList?clientCusPosShiftId=' + clientCusPosShiftId, false);
xhReq.send(null);
var jsonObj = JSON.parse(xhReq.responseText);
使用javascript length属性检查长度
if (jsonObj.length < 1)
alert("kendodropdown have zero data");
绑定数据源
$("#ddlWorker").kendoDropDownList({
dataTextField: "workerName",
dataValueField: "workerID",
autoBind: false,
optionLabel: {
workerName: "--- Please Assign A Worker ---",
workerID: ""
},
// define custom template
template:
'<h5>${ data.workerName }</h5>'
+ '#if(data.AvailableDay_LookID) {#<p>${ data.AvailableDay_LookID }</p>#}#'
+ '#if(data.StartTime && data.EndTime) {#<p>${ data.StartTime } - ${ data.EndTime }</p>#}#',
dataSource: jsonObj
});
答案 1 :(得分:1)
试试这个
var dropdownlist= $("#ddlWorker").kendoDropDownList({
dataTextField: "workerName",
dataValueField: "workerID",
autoBind: false,
optionLabel: {
workerName: "--- Please Assign A Worker ---",
workerID: ""
},
// define custom template
template:
'<h5>${ data.workerName }</h5>' +
'#if(data.AvailableDay_LookID) {#<p>${ data.AvailableDay_LookID }</p>#}#' +
'#if(data.StartTime && data.EndTime) {#<p>${ data.StartTime } - ${ data.EndTime }</p>#}#',
dataSource: {
transport: {
read: {
url: '/Client/LoadWorkerDropdownList?clientCusPosShiftId=' + clientCusPosShiftId,
dataType: "json",
type: "POST"
}
}
}
}).data("kendoDropDownList");
dropdownlist.dataSource.bind("change", function(e) {
var raw = dropdownlist.dataSource.data();
var length = raw.length;
if (length < 1) {
alert("kendodropdown have zero data");
}
});
答案 2 :(得分:0)
如果你的代码可行,那么试试这个
立即检查数据源大小使用“dataSource.one”事件
调用“dataSource.one”事件&amp;检查dataSource大小
var dropdownlist = $("#ddlWorker").kendoDropDownList({
....
....
}).data("kendoDropDownList");
dropdownlist.dataSource.one("change", function() {
//event handled will be called only once.
var raw = dropdownlist.dataSource.data();
var length = raw.length;
if (length < 1)
alert("kendodropdown have zero data");
});
多次检查数据源大小使用“open”方法,检查下面的代码
var dropdownlist = $("#ddlWorker").kendoDropDownList({
....
....
open: function() {
var raw = dropdownlist.dataSource.data();
var length = raw.length;
if (length < 1)
alert("kendodropdown have zero data");
}
}).data("kendoDropDownList");