我有以下Kendo UI
网格。我正在尝试从网格中提醒更新的值。但我收到了以下错误
未捕获的ReferenceError:未定义保存
我们如何解决此错误并显示网格中的所有更新值?
车身
<div id="grid"></div>
<br />
<input type="button" value="Save Row" onclick="save();" />
<input type="button" value="Submit To Server" onclick="" />
<script id="gridItems" type="text/x-kendo-template">
<tr data-uid="#= uid #">
<td title="#= EmpName #">
#= EmpName #
</td>
<td title="#= Department #">
#= Department #
</td>
</tr>
</script>
的Javascript
var records = [
{
"foo": 1,
"EmpName":"A1",
"Department": "D1"
},
{
"foo": 2,
"EmpName":"A2",
"Department": "D2"
}
];
var myDataSource = new kendo.data.DataSource({
data: records,
schema: {
model: {
id: "foo",
fields: {
foo: {type: "number"},
EmpName: {type: "string"},
Department: {type: "string"}
}
}
}
});
var grid = $("#grid").kendoGrid({
dataSource: myDataSource,
columns: ["EmpName", "Department"],
editable: "inline",
selectable: "row",
rowTemplate: kendo.template($("#gridItems").html()),
dataBound: function()
{
//Click on each row
$("#grid tbody tr").on("click", function(e)
{
if (!$(this).hasClass('k-grid-edit-row'))
{
//Make the row editable
$("#grid").data("kendoGrid").editRow($(this));
}
});
}
}).data("kendoGrid");
function save()
{
var row = $("#grid tbody").find(".k-grid-edit-row");
if(row.length == 1)
{
$("#grid").data("kendoGrid").saveRow(row);
}
var updatedData = grid.dataSource.data();
alert(updatedData.length);
for (var i = 0; i < updatedData.length; i++)
{
var dataitem = updatedData[i].EmpName;
alert(dataitem);
}
}
参考