【问题标题】:Kendo UI Grid inline editKendo UI Grid 内联编辑
【发布时间】:2015-07-26 15:54:32
【问题描述】:

您好,我正在尝试做剑道网格,但它不起作用,显示网格但没有显示数据。我不知道出了什么问题。我不知道 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: "&nbsp;", 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
  }
]}

【问题讨论】:

    标签: kendo-ui kendo-grid


    【解决方案1】:

    由于您的数据实际上嵌套在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 } }
    
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-04
      • 1970-01-01
      • 1970-01-01
      • 2016-01-01
      • 2016-10-30
      • 2014-05-28
      相关资源
      最近更新 更多