【问题标题】:Filtering a Sencha Touch 2 store to match field exactly with int value过滤 Sencha Touch 2 存储以将字段与 int 值完全匹配
【发布时间】:2013-02-06 22:30:40
【问题描述】:

我正在尝试过滤 ST2 商店以准确查找具有特定 ID 的项目。默认情况下,ST2 使用 LIKE 运算符过滤存储,这不适用于查找精确的 int (id) 匹配项。经过一番搜索,我发现我需要使用正则表达式来执行此操作,但我无法找出正确的正则表达式。这是我的代码:

var categoriesStore = Ext.getStore('categories');
var category_id = this.config.data.catId;
categoriesStore.filter('category_id', **regex pattern here**);

我没有运气尝试了以下方法:

/^category_id$/

"/^"+category_id+"$/"

我确信我已经很接近了。

【问题讨论】:

  • 试试"^"+category_id+"$"
  • @Qtax 我尝试了您的建议,但这似乎不起作用。 categorieStore 由于应用过滤器而没有显示任何项目。我可以看到,如果我在其上运行 clearFilter(),所有数据都会返回。
  • 另见 stackoverflow.com/questions/5195190/…>

标签: javascript regex filter sencha-touch-2 datastore


【解决方案1】:

当您将模式传递给过滤器时,您不需要将开始/结束斜杠放入正则表达式模式中,这是在某些语言/命令行工具中使用的分隔符。

这应该可以正常工作:

"^"+category_id+"$"

【讨论】:

  • 看到@Qtax 也解决了这个问题
【解决方案2】:

还有一个exactMatch参数可以在filter对象中设置:Filtering a Ext.data.Store by a particular id returns multiple results

【讨论】:

    猜你喜欢
    • 2012-09-13
    • 2015-11-10
    • 2012-07-24
    • 1970-01-01
    • 2012-06-12
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 2012-05-23
    相关资源
    最近更新 更多