【发布时间】:2017-11-29 14:41:03
【问题描述】:
我在使用 Kendo UI Listview 保存对服务器的更改时遇到问题。
DataSource 是这样配置的:
var listViewDataSource = new kendo.data.DataSource({
transport: {
read: {
url: MyServiceURL
},
update: function() {
console.log("test"); // I expected to enter this function
// when the user changes data on the
//client, never happens
}
},
schema: {
Id: "Id",
fields: {
DeptName: {
editable: false,
},
HourRate: {
type: "number",
editable: true
},
ShowOnSavings: {
type: "boolean",
editable: true
},
ShowOnTechnicalCosts: {
type: "boolean",
editable: true
},
ShowOnOtherCosts: {
type: "boolean",
editable: true
}
}
},
sync: function (e) {
console.log("item synched"); //This should be fired after the
// updated data is sent, never
//happens
}
ListView 是这样初始化的:
kendo.bind($("#listview-container"), {
listViewDataSource: listViewDataSource,
onItemSaved: function (e) {
console.log("item saved"); // fired every time the user changes
//an item, as expected
}
})
ListView 正确加载数据。当用户编辑项目时,更改在本地可见(离开编辑模式后)并且按预期触发保存事件。
但是,更改永远不会与服务器同步,我的更新方法永远不会被调用,也永远不会调用任何网络活动。
ListView 保存方法的文档说明如下:
保存编辑的 ListView 项目。触发保存事件。如果不阻止保存事件且验证成功将调用 DataSource 同步方法。
由于我没有在保存事件上调用preventDefault,因此我希望数据源能够同步,但这不会发生。手动调用dataSource.sync() 也无济于事。
我很困惑为什么这不起作用。任何提示表示赞赏。
【问题讨论】:
-
到目前为止,我对 KendoUI 有自己的经验,您可能还需要实现缺少的传输功能(缺少破坏和创建)。还要在模式定义中将“Id”切换为“id”,因为 JavaScript 区分大小写,并且数据源的代码隐藏正在寻找属性“id”。如果您的 id 字段被称为“Id”,它可能会成为一个问题 - 最好将其更改为“entryId”之类的东西。一种解决方法是在“onItemSaved”事件中自行处理通信。
标签: javascript jquery kendo-ui kendo-datasource kendo-listview