Kendo MVVM Grid - 没有执行Transport.create

时间:2014-07-09 20:47:38

标签: kendo-ui kendo-grid kendo-mvvm

我有以下Kendo MVVM网格:

<div id="permissionTypeGrid" data-role="grid"
            data-sortable="true"
            data-scrollable="true"
            data-editable="true"
            data-toolbar="['create', 'save', 'cancel']"
            data-bind="source: permissionTypes"
            data-auto-bind="true"
            data-columns="[
                { 'field': 'PermissionType', 'width': 60  },
                { 'field': 'Description', 'width': 300 },
                { 'field': 'DisplayOrder', 'width': 60 },
                { 'command': [{name: 'destroy', text: 'Delete'}], 'width': 40 }
            ]">
        </div>

以下视图模型:

 self.permissionTypeGrid = kendo.observable({
        isVisible: true,
        permissionTypes: new kendo.data.DataSource({
            schema: {
                parse: function (results) {
                    var permissionTypes = [];
                    for (var i = 0; i < results.Data.Data.length; i++) {
                        var permissionType = {
                            PermissionType: results.Data.Data[i].SystemPermissionTypeCode,
                            Description: results.Data.Data[i].SystemPermissionTypeDescription,
                            DisplayOrder: results.Data.Data[i].DisplayOrder
                        };
                        permissionTypes.push(permissionType);
                    }
                    return permissionTypes;
                }
            },
            transport: {
                read: {
                    url: "/api/ServiceApi?method=Ref/SystemPermissionTypes",
                },
                create: {
                    url: "/api/ServiceApi?method=Ref/SystemPermissionTypes"
                },
                update: {
                    url: "/api/ServiceApi?method=Ref/SystemPermissionTypes"
                },
                destroy: {
                    url: "/api/ServiceApi?method=Ref/SystemPermissionTypes"
                },
                parameterMap: function (options, operation) {
                    if (operation !== "read" && options.models) {
                        return { models: kendo.stringify(options.models) };
                    }
                }
            }
        })
    });
    kendo.bind($("#permissionTypeGrid"), self.permissionTypeGrid);

Transport.read工作正常,但传递的transport.create的url永远不会执行,parameterMap函数也不会执行。如果我向网格添加一条新记录,然后点击&#34;保存更改&#34;,那么不应该调用parameterMap函数吗?此外,读取的http请求按预期进行,但没有为create创建。

1 个答案:

答案 0 :(得分:1)

您的架构需求和ID。

如果您在架构之后添加行model: { id: "DisplayOrder" },,则在您点击保存更改时,您的创建将开始触发。

当然,这不太可能是您想要用于ID的字段,但它应该让您工作。

schema: {
   model: { id: "DisplayOrder" },
   parse: function (results) {
    ...
}