我已经设置了基本的Kendo Grid,并且正在使用服务器端PHP Wrapper库中的DataSourceResult类。
我遇到了一个奇怪的问题……如果我对新记录进行create
然后编辑(不刷新页面),则再次调用create
操作,而不是update
操作。
如果在添加新记录后刷新页面,则对记录进行更改后将正确调用update
操作。
我可以确认create
操作后,DataSourceResult类正在返回正确的数据,包括新记录的id
。
任何想法为什么会发生这种情况(以及如何阻止它)?
谢谢
更新:这是数据源代码。网址中的查询字符串只是为了轻松区分Chrome控制台中的请求。 ajax.php
使用与每个请求一起传递的其他数据来区分请求的不同操作。
data = new kendo.data.DataSource({
transport: {
create: {
url: '/ajax.php?r=gridCreate',
dataType: 'json',
type: 'post',
data: { request: 'grid', type: 'create' }
},
read: {
url: '/ajax.php?request=gridRead',
dataType: 'json',
type: 'post',
data: { request: 'grid', type: 'read' }
},
update: {
url: '/ajax.php?r=gridUpdate',
dataType: 'json',
type: 'post',
data: { request: 'grid', type: 'update' }
},
destroy: {
url: '/ajax.php?r=gridDestroy',
dataType: 'json',
type: 'post',
data: { request: 'grid', type: 'destroy' }
},
parameterMap: function(data, operation) {
if (operation != "read"){
data.expires = moment(data.expires).format('YYYY-MM-DD HH:mm');
}
return data;
}
},
schema: {
data: 'data',
total: 'total',
model: {
id: 'id',
fields: {
id: { editable: false, nullable: true },
code: { type: 'string' },
expires: { type: 'date' },
enabled: { type: 'boolean', defaultValue: true }
}
}
},
pageSize: 30,
serverPaging: true,
serverSorting: true,
serverFiltering: true
});
最佳答案
我也有同样的问题,我已经尝试过了,并且可以正常工作。
.Events(events => events.RequestEnd("onRequestEnd"))
并在此功能中使用以下:
function onRequestEnd(e) {
var tmp = e.type;
if (tmp == "create") {
//RequestEnd event handler code
alert("Created succesully");
var dataSource = this;
dataSource.read();
}
else if (tmp == "update") {
alert("Updated succesully");
}
}
尝试在网格的onRequestEnd事件中使用此代码
var dataSource = this;
dataSource.read();
希望对您有帮助。
关于kendo-ui - 添加新记录后,Kendo Grid调用 'create'操作而不是 'update',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20380473/