将网格中的所有记录提取到数组中

问题描述 投票:0回答:1

单击button时,我想获取网格中的所有数据,这些数据将存储到数组中,因此我可以使用ajax函数解析为php。但是我在网格occLevel_中有一个循环列。我需要帮助,如何使用for循环获取所有occLevel_0 -> 3值。

Full Demo

$("#grid").kendoGrid({
  columns: [
    { field: "Name" },
    { field: "occlevel_0" },
    { field: "occlevel_1" },
    { field: "occlevel_2" },
    { field: "occlevel_3" },
  ],
  dataSource: {
   data: [{
        "Name": "John",
        "occlevel_0": 11,
        "occlevel_1": 31,
        "occlevel_2": 51,
        "occlevel_3": 61
      }, {
        "Name": "Jane",
        "occlevel_0": 12,
        "occlevel_1": 32,
        "occlevel_2": 52,
        "occlevel_3": 62
      }, {
        "Name": "James",
        "occlevel_0": 13,
        "occlevel_1": 33,
        "occlevel_2": 53,
        "occlevel_3": 63
      }],
   schema:{
    model: {
     id: "id",
    }
   }
  },
  editable: true
});


$("#fetch_allData").kendoButton();
var button = $("#fetch_allData").data("kendoButton");
button.bind("click", function(e) {
  var grid = $('#grid').data('kendoGrid').dataSource.data();
  console.log(grid);

  var items = {
    method: "updateOccLevel" //function call in php
  };
  for ( var i=0; i < grid.length; i++ ) {  
    items["Name_" + i] = grid[i]['Name'],
    items["occlvl_" + i] = grid[i]['occlevel_' + i]  // ???
  }; 
  console.log(items);


  /*$.ajax({
    url: "./updateOccLevel.php",
    type: "POST",
    data: items,
    success : function (data) {
          alert('success');
    }         
  });*/ 

});
<div id="grid"></div>
<button id='fetch_allData' >Update Grid</button>
javascript jquery kendo-ui
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.