Home > Web Front-end > JS Tutorial > BUG demo code of findRecord in store of EXTjs4.0_extjs

BUG demo code of findRecord in store of EXTjs4.0_extjs

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

The findRecord: function() method is called in the findRecord method

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


Enter the find method


Copy the code The code is as follows: 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 method
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 < len; i ) {
if (fn.call(scope || me, items[i], keys[i])) {
return i;
}
}
return -1;
},


Please note
value.test(r.data[property]); the BUG occurs here
The property I use here is the "ID" field.
Here It is to query the record with ID==1,
It is done through this loop



Copy code The code is as follows : for (; i < len; i ) {
if (fn.call(scope || me, items[i], keys[i])) {
return i;
}
},


That is,
value.test(r.data[property]) is called every time
This judgment is made through regular expressions
You can test this situation



Copy the code The code is as follows: var value=new RegExp('1');
var b=value.test('15')//This is returned successfully.


I think everyone knows the reason.
When it is judged that ID=1, when an ID starting with 1 is encountered, a problem will be determined at this time.
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