Kendo ui 在服务器端的单个url中获取所有更新的和新创建的模型

Kendo ui 在服务器端的单个url中获取所有更新的和新创建的模型,kendo-ui,kendo-grid,Kendo Ui,Kendo Grid,我使用剑道网格与批编辑。我想把所有修改过的和新创建的模型放在一个url中 假设我在网格中创建了3个新行,并更新/编辑了2个现有行。数据源为每个CRUD操作发出HTTP请求。更改的数据项默认情况下作为模型发送,并按我在datasource中传输的“创建”和更新(传输)部分中声明的方式点击URL。我正在获取在服务器端为“更新”声明的URL中修改(更新)的模型。还可以找到在为“创建”声明的URL中新创建的模型……但我想在一个URL中获得所有修改和新创建的模型。是否可以在一个URL中获得所有(所有修改和

我使用剑道网格与批编辑。我想把所有修改过的和新创建的模型放在一个url中

假设我在网格中创建了3个新行,并更新/编辑了2个现有行。数据源为每个CRUD操作发出HTTP请求。更改的数据项默认情况下作为模型发送,并按我在datasource中传输的“创建”和更新(传输)部分中声明的方式点击URL。我正在获取在服务器端为“更新”声明的URL中修改(更新)的模型。还可以找到在为“创建”声明的URL中新创建的模型……但我想在一个URL中获得所有修改和新创建的模型。是否可以在一个URL中获得所有(所有修改和新创建的)模型

这是我的代码,以便更好地理解

$("#grid").kendoGrid({
        dataSource: {

            transport: {
                read: {
                    url: "LoadPerMeterCostsGridData",
                    type: "POST",
                    contentType: "application/json",
                    dataType: "json"
                },

                update: {
                    url: "UpdatePerMeterCostsData",
                    contentType: "application/json",
                    type: "POST",
                    dataType: "json"
                },
                create: {
                    url: "CreatePerMeterCostsData",
                    contentType: "application/json",
                    type: "POST",
                    dataType: "json",
                },
                parameterMap: function (data, operation) {
                    if (operation != "read") {
                        return kendo.stringify(data.models);
                    }

                }
            },

            serverPaging: false,
            pageSize: 10,
            batch: true,

            schema: {
                model: {
                    id: "PerMeterCostID",
                    fields: {
                        PerMeterCostID: { editable: false },
                        DrillBitSizeID: { editable: true },
                        Form: { editable: true },
                        To: { editable: true },
                        PerMeterCost: { editable: true },
                        ContractID: { editable: false }
                    }
                },
                errors: "Errors"
            },

            error: function (e) {
                alert(e.errors + "grid");
            }
        },
        editable: true,
        pageable: {
            refresh: true,
            pageSizes: true
        },
        toolbar: ["create",
            "save",
            "cancel"
        ],
        sortable: true,
        autoBind: false,
        columns:
        [
            { field: "PerMeterCostID", width: 50, hidden: true, title: "ID" },
            { field: "DrillBitSizeID", width: 100, hidden: true, title: "Consumable" },
            { field: "Form", width: 100, title: " Form " },
            { field: "To", width: 50, title: "To" },
            { field: "PerMeterCost", width: 100, title: "Per Meter Cost" },
            { field: "ContractID", width: 100, hidden: true, title: "ContractID" },

           { command: ["destroy"], title: "Action", width: "175px" }


        ]
    });

    $("#grid ").data("kendoGrid").dataSource.read();

您可以将每个CRUD操作设置为使用相同的url,但对创建和更新使用相同的
url:
属性。但是,您仍将至少收到两个请求(尽管是到相同的url)

这是因为在内部,数据源将数组中由“设置为字段默认值的Id字段项”定义的所有“新”项,以及设置为true的所有
dirty
项推送到另一个数组中。然后,Kendo根据操作的url将这两个数组发送回服务器。(我想是这样的)

避免这种情况的“最简单”方法是确保新对象明确地将其id字段设置为默认值以外的值,并将模型
dirty
prob设置为
true

您可以通过使用
edit
事件覆盖操作来完成此操作

grid.bind('edit', function(e){
    if ( e.model.isNew() ) {
       e.model.id = -1; //
       e.dirty = true; 
       console.log(e.model.isNew()) // should be false
    }
})

这可能是为了避免一个额外的请求而进行的过度杀戮,并且容易出错。我建议您对这两个操作使用相同的url,并接受您将在一个批中获取创建的项目,在另一个批中获取更新的项目。

实际上,我想在更新后比较整个网格数据,并创建一些新行。我只想在客户端或服务器端一次获取整个网格项目(在控制器中)。有什么方法可以得到这个吗?这将对我帮助最大。
 if ( model.isNew()) 
     createdPile.push(model)
 else if ( model.dirty === true)
    updatedPile.push(model)

 //send both piles to the server
grid.bind('edit', function(e){
    if ( e.model.isNew() ) {
       e.model.id = -1; //
       e.dirty = true; 
       console.log(e.model.isNew()) // should be false
    }
})