2016-07-22 67 views
0

我在我的.ts(.js)文件中有一個單擊事件。當用戶點擊時,我正在調用ajax來獲取數據。成功後,我綁定這些數據來創建動態kendo網格(網格數量根據數據而不同)。如何在文檔準備好執行部分代碼?

執行事件後,我想執行一些代碼。但在執行此代碼時,特定的網格不可用。如何等待,直到網格可用然後執行此代碼? jquery文檔準備在同一個點擊事件中不起作用。

$(chkBox).click(() => { 
      var chk = $(event.target); 
      var val = chk.val(); 
      if (chk.prop("checked")) { 
       // code removed for bravity          
       proxyEle.getData(myObject).done(result => { 
       // this div has partial view which binds data from result. 
        $(divGrids).html(<string>result); // this part creates kendo grids dynamcially based on data. 

        // here I want to execute my code on the grid elements 
        //but this code is executing before grid creation is complete. 
        //So my code is not working. Why here? My grid ids are 
        // like "SomeConstName"+chk.val(); this val() I only get here. 

       }).fail(error => { 
        // handle error 
       }); 
       } 
       } 

爲什麼要在那裏執行我的代碼?因爲我使用網格ID作爲「ConstGridName」+ chk.value();

這個Id值我在上面的代碼。這就是爲什麼我想在那裏執行我的代碼。如何延遲我的代碼執行,直到所有網格都準備好了?

回答

0

知道電網完成(和綁定)時,唯一的辦法就是認購DataBound事件(當網格填充數據發射)

.Events(ev => ev.DataBound("onGridDataBound")) 

在那裏,你可以運行你的代碼。

相關問題