Home > Web Front-end > JS Tutorial > body text

EXTjs4.0的store的findRecord的BUG演示代码_extjs

WBOY
Release: 2016-05-16 17:32:27
Original
1083 people have browsed it

在findRecord方法调用了 findRecord: function()这个方法

复制代码 代码如下:

findRecord: function() {
var me = this,
index = me.find.apply(me, arguments);
return index !== -1 ? me.getAt(index) : null;
},

进入find方法
复制代码 代码如下:

find: function(property, value, start, anyMatch, caseSensitive, exactMatch) {
var fn = this.createFilterFn(property, value, anyMatch, caseSensitive, exactMatch);
return fn ? this.data.findIndexBy(fn, null, start) : -1;
},
createFilterFn方法
createFilterFn: function(property, value, anyMatch, caseSensitive, exactMatch) {
if (Ext.isEmpty(value)) {
return false;
}
value = this.data.createValueMatcher(value, anyMatch, caseSensitive, exactMatch);
return function(r) {
return value.test(r.data[property]);
};
},
findIndexBy : function(fn, scope, start){
var me = this,
keys = me.keys,
items = me.items,
i = start || 0,
len = items.length;

for (; i if (fn.call(scope || me, items[i], keys[i])) {
return i;
}
}
return -1;
},

请注意
value.test(r.data[property]);有BUG的地方就出在这里
我这里用property是"ID"字段.
这里是查询ID==1的这条记录record,
它通过这个循环来做的
复制代码 代码如下:

for (; i if (fn.call(scope || me, items[i], keys[i])) {
return i;
}
},

即每次都调用
value.test(r.data[property])
这个判断是通过正则表达式来做的,
大家可以测试一下这个情况
复制代码 代码如下:

var value=new RegExp('1');
var b=value.test('15')//这个是返回成功的。

我想大家都知道原因了,
当判断ID=1的时候,遇到1开头的ID的时候,这个时候就判断出问题了。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!