我有一个带有以下字段的JsonStore:
id
date
time
type
Run Code Online (Sandbox Code Playgroud)
我有收集三个字段(表单date
,time
,type
),并插入一个新的记录进店(我保存单独的商店).我想检查商店中是否已存在具有相同字段值组合的记录,以避免重复输入.
我设法检查另一个商店中的重复ID,如下所示:
find = DepartmentMemberStore.find('member_id', value_from_form);
if (find != -1) {
// popup error window
return;
} else {
// add new record to store
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何检查商店以查看多个字段值是否匹配.
McS*_*tch 16
我在findBy( Function fn, [Object scope], [Number startIndex] )
这种情况下使用过Store .fn
为存储中的每个记录调用该函数,并将当前记录及其相应的id传递给该函数.因此,您可以使用当前记录的字段来比较每个表单字段.
以下是您的情况示例:
var recordIndex = DepartmentMemberStore.findBy(
function(record, id){
if(record.get('date') === date_from_form &&
record.get('time') === time_from_form &&
record.get('type') === type_from_form){
return true; // a record with this data exists
}
return false; // there is no record in the store with this data
}
);
if(recordIndex != -1){
alert("We have a duplicate, abort!");
}
Run Code Online (Sandbox Code Playgroud)