SAPUI5模型过滤器:如何提供多个AND条件

时间:2017-09-29 14:39:19

标签: javascript sapui5

我在我的应用中使用这些过滤器:

    filters: [
                    new sap.ui.model.Filter({
                        and: true,
                        filters: [
                            new sap.ui.model.Filter(Filter condition1),
                            new sap.ui.model.Filter(Filter condition2)
                        ]
                    }

                    ),
                    new sap.ui.model.Filter({
                        and: true,
                        filters: [
                            new sap.ui.model.Filter(Filter condition3),
                            new sap.ui.model.Filter(Filter condition4)
                        ]
                    }),

所以这样工作: 给我所有满足的数据 -

(condition1 AND condition2)OR(condition3 AND condition4)

但是,我想做这样的事情: 给我所有满足的数据 -

(condition1 AND condition2)AND(condition3 AND condition4)

有没有办法做到这一点?我试过这个,但它不能以某种方式工作:

    filters: [
                    new sap.ui.model.Filter({
                        and: true,
                        filters: [
                            new sap.ui.model.Filter(Filter condition1),
                            new sap.ui.model.Filter(Filter condition2)
                        ]
                    }
                    and: true,  
                    ),
                    new sap.ui.model.Filter({
                        and: true,
                        filters: [
                            new sap.ui.model.Filter(Filter condition3),
                            new sap.ui.model.Filter(Filter condition4)
                        ]
                    }),

1 个答案:

答案 0 :(得分:0)

AND是一个传递函数,你可以去

new sap.ui.model.Filter({
    and: true,
    filters: [
        new sap.ui.model.Filter(Filter condition1),
        new sap.ui.model.Filter(Filter condition2),
        new sap.ui.model.Filter(Filter condition3),
        new sap.ui.model.Filter(Filter condition4)
    ]
}

如果你需要分别建立你的子条件,你可以这样做

var subCondition1 = new sap.ui.model.Filter({
    and: true,
    filters: [
        new sap.ui.model.Filter(Filter condition1),
        new sap.ui.model.Filter(Filter condition2)
    ]
}

var subCondition2 = new sap.ui.model.Filter({
    and: true,
    filters: [
        new sap.ui.model.Filter(Filter condition3),
        new sap.ui.model.Filter(Filter condition4)
    ]
}

var finalCondition = new sap.ui.model.Filter({
    and: true,
    filters: [
        subCondition1,
        subCondition2
    ]
}

(代码未经测试)