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