1

我创建了一个基于 odata 服务的剑道网格,如下面的代码所示。这会在列表中显示值,但是当有新记录时这不起作用。这是因为它不仅发送创建的值,还发送列表的文本。

 @model IEnumerable<SE.CloudMonitor.Web.Models.ObjectType>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/CloudMonitor.cshtml";
}


<h2 class="tituloVista">Objetos</h2>
<div id="grid"></div>
<script>
    $(document).ready(function () {
        kendo.culture("es-CO");


        var ObjectType = [      
        @foreach (var item in Model)
        {
             @: { "value": @Html.DisplayFor(modelItem => item.ObjectTypeID)  ,'text':" @Html.DisplayFor(modelItem => item.ObjectTypeName) "},
        }  
        ];

        var crudServiceBaseUrl = "Services/CloudMonitor.svc/Objects",
            dataSource = new kendo.data.DataSource({
                type: "odata",
                transport: {
                    read: {
                        url: crudServiceBaseUrl,
                        dataType: "json"
                    },
                    update: {
                        url: function (data) {
                            return crudServiceBaseUrl + "(" + data.ObjectsID + ")";
                        }
                    },
                    create: {
                        url: crudServiceBaseUrl
                    },
                    destroy: {
                        url: function (data) {
                            return crudServiceBaseUrl + "(" + data.ObjectsID + ")";
                        }
                    }
                },
                batch: false,
                pageSize: 5,
                serverPaging: true,
                schema: {
                    model: {
                        id: "ObjectsID",
                        fields: {
                            ObjectsID: { editable: false, nullable: true },
                            ObjectTypeID: { editable: true, nullable: true },
                            ObjectName: { editable: true, nullable: true }
                        }
                    }
                }
            });

        $("#grid").kendoGrid({
            dataSource: dataSource,
            pageable: true,
            height: 400,
            toolbar: ["create"],
            columns: [
                { field: "ObjectName", width: "150px", title:"Nombre objeto" },
                { field: "ObjectTypeID", width: "150px", values: ObjectType, title: "Tipo objeto" },
                { command: ["edit", "destroy"], title: " ", width: "110px" }],
            editable: "popup"
        });
    });
</script>

更新 2014-02-19 在搜索了很多解决方案后,我发现剑道组合框不起作用。为了解决这个问题,我放置了一个带有选择标签的模板和编辑器,现在它可以正常工作了。

4

0 回答 0