【问题标题】:Extjs store: implement 'find()' in reverse directionExtjs 商店:反向实现'find()'
【发布时间】:2014-09-29 06:21:17
【问题描述】:

因此,Extjs 4.0 有多种方法可以在特定字段中查找特定值。来自文档:

find( fieldName, value, [startIndex], [anyMatch], [caseSensitive], [exactMatch] )

完美运行。

我想要做的是在相反的方向实现同样的事情。例如,如果startIndex 是 100,我想测试记录 99、98、97 等等,直到找到命中。但是,我找不到任何方法来做到这一点。有人可以帮忙吗?

【问题讨论】:

  • “我找不到任何方法。”你到底试过什么?你有什么问题?

标签: extjs store extjs4.2


【解决方案1】:

如果您查看源代码,您会发现 find 只是在 MixedCollection 上调用了方法 findIndexBy

// store:
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;
},

// mixedcollection
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;
},

因此,要获得您想要的结果,您只需创建自己的 find 方法并更改最后一个 for 循环。

【讨论】:

    【解决方案2】:

    没有这样的方法。可能最简单的方法是:

    1. 拨打getRange从0到101
    2. 向后遍历返回的数组以查找记录

    【讨论】:

      猜你喜欢
      • 2012-10-01
      • 2014-03-11
      • 1970-01-01
      • 2015-10-22
      • 2015-08-11
      • 2012-12-21
      • 1970-01-01
      • 2020-03-02
      • 2023-03-31
      相关资源
      最近更新 更多