我正在尝试过滤多个组合框。如果逻辑:( CreatedBy1)&&(TaskStatus1)Image我的代码似乎工作
视图:
<fb:FilterBar id="filterBar" useToolbar="false" search="onPressGo">
<fb:filterGroupItems>
<fb:FilterGroupItem visibleInFilterBar="true" groupName="G1" groupTitle="Group1" name="A8" label="Region">
<fb:control>
<MultiComboBox
id = "Region"
width = "260px"
items="{
path: '/VH_RegionSet',
sorter: { path: 'Text' }
}">
<core:Item key="{Code}" text="{Text}" />
</MultiComboBox>
</fb:control>
</fb:FilterGroupItem>
<fb:FilterGroupItem groupName="G1" groupTitle="Group1" name="A7" visibleInFilterBar="true" label="Road Master Area">
<fb:control>
<MultiComboBox
id = "RoadMasterAreaId"
width = "260px"
items="{
path: '/VH_RoadMasterAreaSet',
sorter: { path: 'Text' }
}">
<core:Item key="{Code}" text="{Text}" />
</MultiComboBox>
</fb:control>
</fb:FilterGroupItem>
<fb:FilterGroupItem groupName="G1" groupTitle="Group1" name="A6" visibleInFilterBar="true" label="Sub-Division/Yard Indicator">
<fb:control>
<MultiComboBox
id = "SubdivYardIndicator"
width = "260px"
items="{
path: '/VH_SubdivYardIndicatorSet',
sorter: { path: 'Text' }
}">
<core:Item key="{Code}" text="{Text}" />
</MultiComboBox>
</fb:control>
</fb:FilterGroupItem>
<fb:FilterGroupItem groupName="G1" groupTitle="Group1" name="A5" visibleInFilterBar="true" label="Track Type">
<fb:control>
<MultiComboBox
id = "TrackType"
width = "260px"
items="{
path: '/VH_TrackTypeSet',
sorter: { path: 'Text' }
}">
<core:Item key="{Code}" text="{Text}" />
</MultiComboBox>
</fb:control>
</fb:FilterGroupItem>
<fb:FilterGroupItem groupName="G1" groupTitle="Group1" name="A4" visibleInFilterBar="true" label="Asset Type">
<fb:control>
<MultiComboBox
id = "AssetType"
width = "260px"
items="{
path: '/VH_AssetTypeSet',
sorter: { path: 'Text' }
}">
<core:Item key="{Code}" text="{Text}" />
</MultiComboBox>
</fb:control>
</fb:FilterGroupItem>
<fb:FilterGroupItem groupName="G1" groupTitle="Group1" name="A3" visibleInFilterBar="true" label="Created By">
<fb:control>
<MultiComboBox
id = "CreatedBy"
width = "260px"
items="{
path: '/VH_CreatedBySet',
sorter: { path: 'Text' }
}">
<core:Item key="{Code}" text="{Text}" />
</MultiComboBox>
</fb:control>
</fb:FilterGroupItem>
<fb:FilterGroupItem groupName="G1" groupTitle="Group1" name="A2" visibleInFilterBar="true" label="Characteristic">
<fb:control>
<MultiComboBox
id = "CharacteristicId"
width = "260px"
items="{
path: '/VH_CharacteristicSet',
sorter: { path: 'Text' }
}">
<core:Item key="{Code}" text="{Text}" />
</MultiComboBox>
</fb:control>
</fb:FilterGroupItem>
<fb:FilterGroupItem groupName="G1" groupTitle="Group1" name="A1" visibleInFilterBar="true" label="Task Status">
<fb:control>
<MultiComboBox
id = "TaskStatus"
width = "260px"
items="{
path: '/VH_TaskStatusSet',
sorter: { path: 'Text' }
}">
<core:Item key="{Code}" text="{Text}" />
</MultiComboBox>
</fb:control>
</fb:FilterGroupItem>
控制器:
onPressGo: function (oEvent) {
var oTaskFilter = [];
var afinalFilter = [];
var aTaskFilter = [];
var aQuery = ["Region","RoadMasterAreaId","SubdivYardIndicator","TrackType","AssetType","CreatedBy","CharacteristicId","TaskStatus"];
if (oEvent.getParameters().refreshButtonPressed) {
this.onRefresh();
}
else {
for(var i= 0; i< aQuery.length ; i++){
var sQuery = this.byId(aQuery[i]).getSelectedKeys();
if(sQuery){
for(var j=0 ; j< sQuery.length ; j++){
oTaskFilter.push(new Filter({
path : aQuery[i],
operator : FilterOperator.EQ,
value1: sQuery
}));
aTaskFilter=aTaskFilter.concat(oTaskFilter);
}
}
afinalFilter=afinalFilter.concat(aTaskFilter);
}
this._applySearch(afinalFilter);
}
},
但我正在尝试:( CreatedBy1)&&(TaskStatus1和TaskStatus2)屏幕将显示“No Matching found”。不知何故,如果我在同一个ComboBox中选择了多个值,它就无法工作。 Image
尝试使用bAnd = false定义OTaskFilter = new sap.ui.model.Filter(aFilters, bAnd);
并将过滤器放在此过滤器的filters数组中,然后重试。
这将确保您收集的所有过滤器都与OR连接。
我这样做了,它确实在user1 with taskStatus1&taskStatus2时进行过滤。但是,当我只选择user1和user2时,它不会过滤。 Image
onPressGo: function (oEvent) {
var oTaskFilter = [];
var afinalFilter = [];
var aTaskFilter = [];
var aQuery = ["Region","RoadMasterAreaId","SubdivYardIndicator","TrackType","AssetType","CreatedBy","CharacteristicId","TaskStatus"];
if (oEvent.getParameters().refreshButtonPressed) {
this.onRefresh();
}
else {
for(var i= 0; i< aQuery.length ; i++){
var sQuery = this.byId(aQuery[i]).getSelectedKeys();
if(sQuery){
for(var j=0 ; j< sQuery.length ; j++){
oTaskFilter.push(new Filter({path : aQuery[i],
operator : FilterOperator.EQ,
value1: sQuery
})
);
aTaskFilter.push(new Filter (oTaskFilter,false));
}
}
afinalFilter.push(new Filter(aTaskFilter,true));
}
this._applySearch(afinalFilter);
}
},