无法更新剑道网格中的值-无法读取未定义的“数据"属性 [英] Cannot update value in Kendo-grid - cannot read 'data' property of undegined
问题描述
我更新剑道格时在选项HTML元素所选择的值被改变.但是,当我尝试更新浏览器控制台中的网格内联中的值时,会打印"kendo.web.min.js:13 Uncaught TypeError:无法读取未定义的属性'data'".
I am updating Kendo-grid when the selected value in option HTML element is changed. But when I try to update the value in the grid inline in the browser's console is printed "kendo.web.min.js:13 Uncaught TypeError: Cannot read property 'data' of undefined".
我怎么了?
< script >
$(document).ready(function() {
// on changing zone option selector
$('#SelectProviderZoneForPrices').change(function (e) {
var zoneId = $(this).val();
var productId = $('#SelectProviderForPrices').val();
$.ajax({
type: "GET",
url: "@Html.Raw(Url.Action("LoadZoneWeights", "ShippingZonableByWeight"))",
success: loadPrices, // loads the shipping providers which delivers by zones
dataType: 'json',
data: { ProviderId: productId, ZoneId: zoneId }});
});
// loads prices
function loadPrices(data) {
var grid = $('#shippingProviderWeightPrice-grid').getKendoGrid();
grid.dataSource.data(data.Data); // my backend returns DataSourceResult
grid.refresh();
}
// load Kendo-grid
$("#shippingProviderWeightPrice-grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: {
url: "@Html.Raw(Url.Action("ActionMethod", "Controller"))",
type: "GET",
dataType: "json"
},
update: {
url: "@Html.Raw(Url.Action("ActionMethod", "Controller"))",
type: "POST",
dataType: "json"
}
},
schema: {
total: "Total",
errors: "Errors",
model: {
fields: {
ProviderWeightsId: {
editable: false,
visible: false,
type: "number"
},
ZoneId: {
editable: false,
visible: false,
type: "number"
},
ZoneName: {
editable: false,
visible: false,
type: "string"
},
WeightFrom: {
editable: false,
visible: true,
type: "number"
},
WeightTo: {
editable: false,
visible: true,
type: "number"
},
Price: {
editable: true,
visible: true,
type: "number"
}
}
}
},
requestEnd: function(e) {
if (e.type == "update") {
this.read();
}
},
error: function(e) {
display_kendoui_grid_error(e);
this.cancelChanges();
},
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
pageable: {
refresh: true,
numeric: false,
previousNext: false,
info: false
},
editable: {
confirmation: true,
mode: "inline"
},
scrollable: false,
columns: [{
field: "WeightFrom",
title: "Weight From",
format: "{0:n3}",
width: 100
}, {
field: "WeightTo",
title: "Weight To",
format: "{0:n3}",
width: 100
}, {
field: "Price",
title: "Price",
format: "{0:n3}",
width: 100
}, {
command: [{
name: "edit",
text: "Edit"
}]
}]
});
}); < /script>
<fieldset>
<legend><strong>Manage Weights</strong>
</legend>
<table class="adminContent">
<tr>
<td class="adminTitle">Select Provider</td>
<td class="adminData">
<select id="SelectProviderForPrices" name="ProviderId">
<option value="0">- Select Provider -</option>
</select>
</td>
</tr>
<tr>
<td class="adminTitle">Select Zone</td>
<td class="adminData">
<select id="SelectProviderZoneForPrices" name="ProviderId">
<option value="0">- Select Zone -</option>
</select>
</td>
</tr>
</table>
</fieldset>
<br/>
<div id="shippingProviderWeightPrice-grid">
</div>
推荐答案
我发现了问题.我在网格的数据源模型中删除了id属性,这导致了我的问题.我不知道为什么这么大的麻烦-特别是当我可以拥有没有ID的对象时.但是现在可以了.
I found the problem. I was removed the id property in my datasource-model of the grid and that caused my problems. I don't know why it is so big deal - especially when I could have objects without ID. But now it is fine.
id: "ProviderWeightsId",
fields: {
ProviderWeightsId: { editable: false, visible: false, type: "number" },
ZoneId: { editable: false, visible: false, type: "number" },
ZoneName: { editable: false, visible: false, type: "string" },
WeightFrom: { editable: false, visible: true, type: "number" },
WeightTo: { editable: false, visible: true, type: "number" },
Price: { editable: true, visible: true, type: "number" }
}
这篇关于无法更新剑道网格中的值-无法读取未定义的“数据"属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!