0
任何想法如何在插入或更新下面的代码结构时对重复值进行验证?从数据源插入或更新时防止重复值
在创建或更新事件之前,我在哪里以及如何添加验证以验证网格中存在重复记录?
感谢您的指导提前。
var ds = new kendo.data.DataSource({
transport : {
read : {
url : 'readAttribute/',
dataType : 'json',
type : 'POST',
complete : function(e) { }
},
create : {
url : 'save/',
dataType : 'json',
type : 'post',
contentType : 'application/json',
complete : function(e) {
$('#dataGrid').data('kendoGrid').dataSource.read();
}
},
update : {
url : 'update/',
dataType : 'json',
type : 'post',
contentType : 'application/json',
complete : function(e) {
$('#dataGrid').data('kendoGrid').dataSource.read();
}
},
destroy : {
url : 'delete/',
dataType : 'json',
type : 'post',
contentType : 'application/json',
complete : function(e) {
$('#dataGrid').data('kendoGrid').dataSource.read();
}
},
parameterMap : function(options, operation) {
if ((operation == 'create' || operation == 'update') && options.models) {
var valueData = options.models;
for (var i = 0; i < valueData.length; i++) {
valueData[i]['valTypeId'] = $("#valTypeDropDown").data("kendoDropDownList").value();
}
var valFullData = {};
valFullData['val_data'] = valueData;
valFullData['val_type_id'] = $("#valTypeDropDown").data("kendoDropDownList").value();
return kendo.stringify(valFullData);
}
if (operation == 'destroy') {
return kendo.stringify(options.models);
}
if (operation == 'read') {
return {
valTypeId : $("#valTypeDropDown").data("kendoDropDownList").value()
};
}
}
},
batch : true,
pageSize : com.babysister.client.Configuration.Constants.ListConfig.pageSize,
sortable : true,
scrollable : true,
schema : {
model : {
id : "id",
fields : {
id : {
type : "number"
},
name : {
type : "string",
validation: {
required: { message: "Name is required!" }
}
},
valTypeId : {
type : "number"
}
}
}
}
});
嗨,编辑事件是在数据加载之前做的吗?我们可以在点击创建或更新事件之后验证它,然后再发送回服务器端? – Chang
来自文档:'当用户编辑或创建数据项时触发'。因此,您可以使用它来检查输入到网格中的数据以查看它是否是重复数据,这与将其保存返回无关到服务器。 – CodingGorilla
你..但任何想法,我们可以验证后,用户插入/修改值?从你分享的链接是在用户插入新值之前,因此不适合我用来验证同一列中的重复值.... :( – Chang