這取決於您何時進行驗證。
如果您要驗證時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以接受/拒絕修改。 –