Dojo dgrid dstore 集合 - “或”过滤器不起作用

Posted

技术标签:

【中文标题】Dojo dgrid dstore 集合 - “或”过滤器不起作用【英文标题】:Dojo dgrid dstore collection - "or" filter not working 【发布时间】:2016-03-30 13:39:31 【问题描述】:

我正在使用 Dojo dgrid,但在使用“or”语句进行 dstore 过滤时遇到问题。

var today = new Date();
today.setHours(0,0,0,0);

var start_date= new Date();
start_date.setDate(today.getDate() - 5);
start_date.setHours(0,0,0,0); 

grid.set('collection', store.filter(
    new store.Filter().or(
            new store.Filter().gte('datefield1', start_date).lte('datefield1',today),
            new store.Filter().gte('datefield2', start_date).lte('datefield2',today)
    )
)); 

当它们分开时,这两个条件都很完美,但是当我将它们放在“或”过滤器中时,它就像“and”语句一样:两者都必须为“true”才能返回值。

如何使“或”语句在dojo dgrid dstore中正常工作?

【问题讨论】:

【参考方案1】:

问题已由 SitePen 的 kfranqueiro 在其 GitHub 上解决。 非常感谢他的参与。

store.filter(function (item) 
    return (item.datefield1 >= start_date && item.datefield1 <= today) ||
        (item.datefield2 >= start_date && item.datefield2 <= today);
);

完整讨论: https://github.com/SitePen/dgrid/issues/1265

【讨论】:

肯总是来救援! :D

以上是关于Dojo dgrid dstore 集合 - “或”过滤器不起作用的主要内容,如果未能解决你的问题,请参考以下文章