[英]Kendo UI Grid inline edit
嗨,我正在嘗試做劍道網格,它不起作用,顯示網格但沒有顯示數據。 我不知道怎么了 我不知道parametersMap是如何工作的。 請幫我。
控制者
public ActionResult GetGeo(int id)
{
var list = data.getGeoList(id);
return Json(new {list}, JsonRequestBehavior.AllowGet);
}
public ActionResult UpdateGeo(int id)
{
var success = data.UpdatetGeo(id);
return Json(new { Success = success }, JsonRequestBehavior.AllowGet);
}
public ActionResult DeleteGeo(int id)
{
var success = data.DeletetGeo(id);
return Json(new { Success = success }, JsonRequestBehavior.AllowGet);
}
public ActionResult CreateGeo(GeoContent model)
{
var success = data.CreateGeo(model);
return Json(new { Success = success }, JsonRequestBehavior.AllowGet);
}
這是腳本
<script>
$(document).ready(function () {
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "/Home/GetGeo/",
dataType: "json",
contentType: "application/json",
data: {id:5}
},
update: {
url: "/Home/UpdateGeo",
dataType: "json",
contentType: "application/json"
},
destroy: {
url: "/Home/DeleteGeo",
dataType: "json",
contentType: "application/json"
},
create: {
url: "/Home/CreateGeo",
dataType: "json",
contentType: "application/json"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "GeoId",
fields: {
GeoId: { editable: false, nullable: true },
ContentId: { editable: false, nullable: true },
Latitude: { type: "number", validation: { required: true, min: 1 } },
Longitude: { type: "number", validation: { required: true, min: 1 } },
}
}
}
});
$("#grid4").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 550,
toolbar: ["create", "save", "cancel"],
columns: [
{ field: "Latitude", title: "Latitude", width: 120 },
{ field: "Longitude", title: "Longitude", width: 120 },
{ command: "destroy", title: " ", width: 150 }],
editable: true
});
});
Json數據返回: http:// localhost:53232 / Home / GetGeo?id = 5
{"list": [
{
"GeoId":1,
"ContentId":5,
"Latitude":4.716168,
"Longitude":-70.78373
},{
"GeoId":2,
"ContentId":5,
"Latitude":4.718171,
"Longitude":-70.76253
}
]}
由於您的數據實際上是嵌套在list
元素上的,因此您需要添加到架構data: "list"
。 它看起來應該像這樣:
schema: {
data:"list",
model: {
id: "GeoId",
fields: {
GeoId: { editable: false, nullable: true },
ContentId: { editable: false, nullable: true },
Latitude: { type: "number", validation: { required: true, min: 1 } },
Longitude: { type: "number", validation: { required: true, min: 1 } }
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.