2016-08-19 50 views
0

我想在Kendo Combobox中一起使用DataBound和AutoBind。 但無法使用它。 我的DataBound用於插入第一個項目到列表中,如果我使用AutoBind ='false',那麼我無法設置它。如何使用Databound和AutoBind一起用於Kendo Combobox

$("#Number").kendoComboBox({ 
     dataTextField: "NUM", 
     dataValueField: "ID", 
     filter: "startwith", 
     autoBind: false, 
     suggest:true, 
     minLength: 5, 
     dataBound: function() { 
       var dataSource = this.dataSource; 
       var data = dataSource.data(); 
       if (!this._adding) { 
        this._adding = true; 
        if (IS_ANALYST == 'Y') { 
         dataSource.insert(0, { 
          "NUM": "Create New Analysis", 
          "ID": -1 
         }); 
         this.select(function (dataItem) { 
          return dataItem.NUM === "Create New Analysis"; 
         }); 
        } 
        else { 
         dataSource.insert(0, { 
          "NUM": "Select", 
          "ID": -2 
         }); 
         this.select(function (dataItem) { 
          return dataItem.NUM === "Select"; 
         }); 
        } 
        this._adding = false; 
       } 
      }, 
}); 

那麼如何解決這個問題。 我想使用AutoBind ='false'並且還需要插入第一個項目,如圖所示 對此的任何替代方法? 在此先感謝!

回答

0

你爲什麼不能在Open事件嘗試像

<script> 
function combobox_open(e) { 
    // handle the event 
} 

var combobox = $("#Number").data("kendoComboBox"); 
combobox.bind("open", combobox_open); 
</script> 
+0

感謝answer..I通過使用不同的方法解決了這個問題..我已經發布了答案.. – SantyEssac

0

我們可以在數據源使用請求結束:

requestEnd: function (e) { 
         if (IS_ANALYST == 'Y') { 
          e.response.unshift({ ID: -1, NUM: 'Create New Analysis' }); 
          } 
         else { 
          e.response.unshift({ ID: -2, NUM: 'Select' }); 
          } 
        }, 
相關問題