这取决于您何时进行验证。
如果您要验证时store.load();
被调用,那么我建议如下:
myStore.on('beforeload', function(store, loadOptions) {
var isValid = true;
var modifiedRecs = store.getModifiedRecords();
Ext.each(modifiedRecs, (function(record, index, modifiedArray) {
// do validation here
// if validation failed, use the following two lines of code:
// isValid = false;
// return false; // this exits modifiedRecs.each
}, this);
return isValid; // If falsey, this return statement cancels loading.
// Note: the 'loadexception' event will be now be fired
// by myStore if isValid is falsey.
});
如果您要验证每当数据变化在店里,然后使用以下命令:
myStore.on('beforesave', function(store, data) {
// simply do validation against `data`.
// data will contain an array of records for each type of action that
// was being saved, e.g., data['update'] === [updatedRec1, ...].
// if validation failed, just `return false` to cancel saving.
});
这里的这意味着什么是falsey。
只需在商店(在插入,更新之前)听取适当的'before'事件,执行验证并返回true/false以接受/拒绝修改。 –