为什么KendodataSouce.transport.update方法不向服务器发送数据?

Why Kendo dataSouce.transport.update method do not send data to the server?

我有一个 Kendo UI TreeList,其中每一行都显示一个复选框。如果用户单击该复选框,则会向服务器发送请求并保存数据。不幸的是,我做错了什么因为:

我做错了什么?

我认为关于我如何设置那个项目的问题已经改变了。如您所见,我遍历了来自 dataSource.data() and the item.checked and item.dirty properties are updated. If I understand correctly the documentation 的数据集,然后此更改应触发同步方法。它不会触发同步方法,这就是我在方法中调用它的原因。

我的另一个问题是关于应该发送到服务器的数据结构。它基于架构,对吗?因此,一旦我可以实现请求将对象发送到服务器,我应该创建一个类似的 C# POCO 作为模型,我可以读取 webapi 控制器中的数据。

文档中有一个 saveRow() 方法,但我无法将该代码转换为 angular。在这种情况下有人可以帮助我吗?

//this row is my problem
var treeList = $("#treeList").data("kendoTreeList");
var dataSource = new kendo.data.TreeListDataSource({
                transport: {
                    read: {
                        url: configurationService.goNoGoWebApiRootUrl + 'AreaPathDependencies/Get/ChildrenMarked/' + selectedAreaPathIdFromModalService,
                        dataType: "json",
                        type: "get"
                    },
                    update:
                        {
                            url: configurationService.goNoGoWebApiRootUrl + 'AreaPathDependencies/Update/AreaPathDependencies',
                            dataType: "json",
                            type: "post"
                        },
                    parameterMap: function (options, operation) {
                        if (operation !== "read" && options.models) {
                            return { models: kendo.stringify(options.models) };
                        }
                    }
                },
                schema: {
                    model: {
                        id: "id",
                        parentId: "parentId",
                        fields: {
                            Id: { type: "number", editable: false, nullable: true },
                            ParentId: { type: "number", editable: false, nullable: true },
                            Name: { type: "string", editable: false, nullable: true },
                            Checked: { type: "boolean", editable: true, nullable: false }
                        }
                    }
                }
            });

            vm.treeListOptions = {
                dataSource: dataSource,
                sortable: false,
                editable: false,
                columns: [
                    {
                        field: "checked",
                        title: "Selected",
                        template: checkBoxTemplate,
                        width: 32
                    },
                    { field: "name", title: "Area Path", width: "200px", expandable: true },
                    { field: "fullPath", title: "FullPath", width: "500px" },
                ],
                save: onSave,
                change: onChange,
                sync: sync,
                autoSync: true,
            };

        }

        function checkboxOnclick(selectedId) {
            console.log('checkboxOnclick', selectedId);
            var data = vm.treeListOptions.dataSource.data();
            for (var i = 0; i < data.length; i++) {

                if (selectedId == data[i].id) {
                    data[i].set("checked", true);
                    //data[i].dirty = true;
                }
            }

            vm.treeListOptions.dataSource.sync();

            //console.log('flush', vm.treeListOptions.dataSource.data());
        }

好吧 batch: true 必须设置才能使 parameterMap 正常工作,因为模型参数只有在批处理选项为启用。 (parameterMap docs)

关于第二个问题 - 我不太确定,但正如 sync 文档中所述,

The sync method will request the remote service if:

  • the transport.create option is set and the data source contains new data items
  • the transport.destroy option is set and data items have been removed from the data source
  • the transport.update option is set and the data source contains updated data items

我对此的理解 - 要使 sync 方法正常工作,您需要 return 更新记录。请检查 update/delete return 的服务器方法是否是这样。