今天在使用Store.find方法重store中找对应的Record的Index时出了点小BUG,找到的Index有点偏差,找code=‘A’的Index却找到了是code=‘APPROVE’的,仔细看了下API文档才发现查找字符串时只是“键值必须以这个字符串开头”,果断修改为正则表达式的find。
Store.find的Api如下:
[color=cyan]find( String property, String/RegExp value, [Number startIndex], [Boolean anyMatch], [Boolean caseSensitive] ) : Number
使用指定的键/值对,在记录中查找第一个复合条件的对象的序号。
使用指定的键/值对,在记录中查找第一个复合条件的对象的序号。
参数:
property : String
对象的一个属性
value : String/RegExp
要么是一个字符串,键值必须以这个字符串开头; 要么是用来测试键值的一个正则表达式。
startIndex : Number
(可选) 起始下标
anyMatch : Boolean
(可选) 如果为true,将进行任意匹配,而不仅仅是开头
caseSensitive : Boolean
(可选) 如果为true,比较时对大小写敏感
返回值:
Number
符合条件的序号,或者-1
[/color]
Store.find的Api如下:
[color=cyan]find( String property, String/RegExp value, [Number startIndex], [Boolean anyMatch], [Boolean caseSensitive] ) : Number
使用指定的键/值对,在记录中查找第一个复合条件的对象的序号。
使用指定的键/值对,在记录中查找第一个复合条件的对象的序号。
参数:
property : String
对象的一个属性
value : String/RegExp
要么是一个字符串,键值必须以这个字符串开头; 要么是用来测试键值的一个正则表达式。
startIndex : Number
(可选) 起始下标
anyMatch : Boolean
(可选) 如果为true,将进行任意匹配,而不仅仅是开头
caseSensitive : Boolean
(可选) 如果为true,比较时对大小写敏感
返回值:
Number
符合条件的序号,或者-1
[/color]
Store.find方法使用正则表达式解决查找偏差问题
在使用Store.find方法查找store中对应Record的Index时遇到偏差问题,通过修改查找方式为正则表达式成功解决。详细解释了Store.find方法的API文档,包括参数和返回值,并分享了解决实际问题的经验。

被折叠的 条评论
为什么被折叠?



