剑道数据源中的'options'参数



现在我正在学习使用kendoi开发web应用程序,当我尝试使用自定义弹出kendoWindow而不是kendo内置编辑窗口更新网格数据时,我不知道如何将请求发送到远程服务,所以我尝试在本页的官方api文档中找到答案,但是出现了一个新的问题,显示为以下代码:

<script>
    var dataSource = new kendo.data.DataSource({
        transport: {
            read  : function (options) {
                /* implementation omitted for brevity */
            },
            update: function (options) {
                // make JSONP request to http://demos.kendoui.com/service/products/update
                $.ajax({
                    url     : "http://demos.kendoui.com/service/products/update",
                    dataType: "jsonp", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
                    // send the updated data items as the "models" service parameter encoded in JSON
                    data    : {
                        models: kendo.stringify(options.data.models)
                    },
                    success : function (result) {
                        // notify the data source that the request succeeded
                        options.success(result);
                    },
                    error   : function (result) {
                        // notify the data source that the request failed
                        options.error(result);
                    }
                });
            }
        },
        batch    : true,
        schema   : {
            model: { id: "ProductID" }
        }
    });
    dataSource.fetch(function () {
        var product = dataSource.at(0);
        product.set("UnitPrice", 20);
        dataSource.sync(); makes request to http://demos.kendoui.com/service/products/update
    });
</script>

这是一个示例,说明如何将update指定为一个函数,以向远程服务发出HTTP请求

我的问题是什么是参数'选项'是传递给读取和更新功能。我找到的唯一线索是运输的参数。parametermap函数,但我不确定它们之间是否有一定的关系,所以希望有人给我解释一下

options参数是您已经发现的。KendoUI允许您为它的数据源类的数据访问方法指定一个函数,而不是一些配置。

如果你指定了一个函数,kendoUI怎么知道你什么时候完成了加载数据?它不能。因此,有这个选项变量传递给您的函数(实际上,它可以有每个名称,例如dfhajkfhd),您可以调用它来让kendoUI了解您的进度。为此,它有successerror方法,您可以调用它们。

你从kendo-docs中抄来的注释,就是这么说的。

或者你质疑的是不同的东西?

非常感谢那些回答这个问题的人,并试图

我已经从我在问题中链接的kendo-docs底部找到了答案。

  1. 创建了一个新的'dataSource'对象并定义了读取并在其中更新传输
  2. 当数据源准备好时,使用
  3. dataSource的'get'方法来获取我需要更新的数据项通过id。
  4. 使用'set'方法更新数据并使用'sync'方法提交

最后一步是同步数据到数据库下面是我使用的代码

var updateDataSource = new kendo.data.DataSource({
    type: "odata",
    transport: {
        read: {
            url: "/api/odata/PEMEP/TaskInformations/?"
        },
        update: {
            url: "/api/odata/PEMEP/TaskInformations/?",
            type: "PUT",
            dataType: "json",
        },
    },
    schema: {
        model: {
            id: "_id"
        }
    },
    sync: function() { // close edit window when update request finished
        $("#window").data("kendoWindow").close();
    },
    error: function(e) {
        console.log(e.status);
    }
});
updateDataSource.fetch(function() {
    var task = updateDataSource.get(id); // get dataitem by id
    task.set("status", status); // set new values
    task.set("retreatReason", retreatReason);
    updateDataSource.sync(); //submit the change 
});

最新更新