javascript - 更新不适用于 Kendo 数据源

标签 javascript kendo-ui kendo-datasource

我的 Kendo 数据源有问题,更新从未触发,而修改后的对象可以很好地触发更改。

数据源非常简单:

    collection: new kendo.data.DataSource({
        autoSync: false,
        batch: true,
        transport: {
            read: {
                url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignettes_Read",
                dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
            },
            update: {
                url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignette_Update",
                dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
            },
            schema: {
                model: {
                    id: "Id"
                }
            }
        },
        change: function (e) {

            console.log(this);
            console.log(e);

            //Not working too
            //if (e.action == "itemchange") {
            //    debugger;
            //    vignettesViewModel.collection.pushUpdate(e.items[0]);
            //}

            $('.vignette').detach();
            for (var i = 0; i < vignettesViewModel.collection.data().length; i++) { 
                vignettesViewModel.createVignetteUI(vignettesViewModel.collection.data()[i]);                    
            }

            vignettesViewModel.init()
        }
    })

对于测试,自动同步设置为 false,批处理设置为 true。

后来在代码中,我更新了数据源,并通过sync()方法显式触发了数据源

    //Some logic up
        var data_hospit = vignettesViewModel.getByUid($(ui.element).data('uid'));
    //Another logic
        data_hospit.set('date_debut', cellDepart.data('date'));
        data_hospit.set('date_fin', cellArrivee.data('date'));
        data_hospit.set('PrenomNomEtDateDeNaissance', 'toto');

        vignettesViewModel.collection.sync();

更新没有被触发,但我清楚地看到对象更改是通过更改函数进行的。 那么为什么 update 永远不会被触发呢? 我已经用 id : 'Id' 很好地定义了模型,如果我将更新字符串更改为虚拟函数alert(),这也不起作用。 我尝试使用pushUpdate“强制”更新,但出现错误“未定义函数”

感谢您的帮助

最佳答案

schema 不是 transport 的一部分,您写道:

   transport: {
        read: {
            url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignettes_Read",
            dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
        },
        update: {
            url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignette_Update",
            dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
        },
        schema: {
            model: {
                id: "Id"
            }
        }
    },

它应该是:

   transport: {
        read: {
            url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignettes_Read",
            dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
        },
        update: {
            url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignette_Update",
            dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
        }
    },
    schema: {
        model: {
            id: "Id"
        }
    }

关于javascript - 更新不适用于 Kendo 数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26254341/

相关文章:

javascript - 黑名单 React 组件

javascript - KendoUI 网格内联编辑 : focus cell on doubleclick

jquery - Kendo UI 动态更改数据源字符串 (XML)

javascript - Kendo html 编辑器

javascript - 如何获取 KendoDataSource 的 JSON 部分

kendo-ui - kendogrid 上的多个过滤器不起作用

javascript - Kendo 网格 - 获取当前编辑行

javascript - 三元运算符未执行错误语句

javascript - 找不到事件定义

javascript - 我如何计算对 DESCRIPTION 或 ACCEPTANCE CRITERIA 字段的更改次数