更新不与Kendo数据源一起使用

时间:2014-10-08 10:10:53

标签: javascript kendo-ui kendo-datasource

我遇到了Kendo Datasource的问题,在使用修改过的Object很好地解决了更改时,永远不会触发更新。

数据源非常简单:

    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,批处理设置为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();

更新未被触发,但我看到更改的对象通过更改功能。 那么为什么更新从未被解雇? 我已经很好地定义了具有id:'Id'的模型,如果我将更新字符串更改为虚拟函数alert(),这也不起作用。 我试图用pushUpdate“强制”更新,但我收到错误“未定义的函数”

感谢您的帮助

1 个答案:

答案 0 :(得分: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"
        }
    }