2

我对 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()
        }
    })

对于测试,autosync 设置为 false,batch 设置为 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“强制”更新,但出现“未定义函数”错误

谢谢你的帮助

4

1 回答 1

2

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"
        }
    }
于 2014-10-08T10:26:43.073 回答