2017-02-08 27 views
0

我有ID =「gridtemplate」劍道網格上定義的記錄ID,如下圖所示:劍道網 - 如何獲取點擊模板按鈕

 <div> 
      <h4>Download a data import template</h4> 
      <div data-role="grid" 
       data-editable="inline" 
       data-toolbar="['create', 'save']" 
       data-columns="[ 
           { 'field': 'TemplateID', 'hidden': 'true', 'width': 270 }, 
           { 'field': 'TemplateType' }, 
           { 'field': 'FileName','title': 'FileName'}, 
       {command:{ text: 'download', click: viewModel.Download, name:'Download' } } 

          ]" 
       data-bind="source: templates, 
         visible: isVisible, 
         events: { 
          save: onSave, 
          edit: onEdit 
         }" 
       style="height: 200px"></div> 
     </div> 

在點擊每行的下載按鈕,我想獲取與該行關聯的記錄標識。我有如下定義視圖模型我的一個函數調用下載:

var viewModel = kendo.observable({ 
    isVisible: true, 
    Download: function (e) { 
     console.log(id);//want to see the TemplateID here 
    } 
}); 

作爲比較新的劍道,我不知道怎麼去說。請幫忙。提前致謝。

回答

1

你應該能夠獲得點擊的按鈕行的DataItem的下載功能,像這樣:

var grid = this, 
    dataItem = grid.dataItem(e.currentTarget.closest("tr")); 

然後與DataItem的,您可以訪問所有模型的字段。

+0

工作就像一個魅力。可惜我的upvote無法錄製。謝謝 –

+0

你可以接受答案:) – Shai

0

你可以試試這個:

var viewModel = kendo.observable({ 
    isVisible: true, 
    Download: function (e) { 
     var grid = $("#gridtemplate").data("kendoGrid"); //assuming the grid name is gridtemplate 
     var selectedItem = grid.dataItem(grid.select()); 
     console.log(selectedItem.TemplateID); 
    } 
});