0

我有一个 kendo 下拉列表及其工作,我只是想知道我是否可以放置一条消息,当 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"
                    }
                }
            }

        });

谢谢。

4

3 回答 3

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长度属性检查长度

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 

        });
于 2013-09-13T04:13:20.630 回答
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");
    }
});
于 2013-09-13T09:28:34.470 回答
0

如果您的代码可行,请尝试此操作

一次检查数据源大小使用“dataSource.one”事件

调用“dataSource.one”事件并检查数据源大小

 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");

 });

要多次检查数据源大小,请使用“打开”方法,检查以下代码

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");
于 2013-09-13T07:59:10.433 回答