我需要使用多个过滤器项过滤odata服务并将结果集绑定到表。这整个动作将在单击搜索按钮时发生。下面是我的Onsearch事件代码,该代码无法读取功能,并且不返回结果,也无法将其绑定到表。有人可以请我帮忙吗?
onFinalFilter: function (oEvent) {
debugger;
var oPlant = this.getView().byId("plant").getValue();
var oName1 = this.getView().byId("name1").getValue();
var oName2 = this.getView().byId("name2").getValue();
var oState = this.getView().byId("State").getValue();
var oCity = this.getView().byId("city").getValue();
var oZip = this.getView().byId("zip").getValue();
var oCompanyCode = this.getView().byId("companyCode").getValue();
var p = new Filter("WERKS", FilterOperator.EQ, oPlant);
var n1 = new Filter("NAME1", FilterOperator.EQ, oName1);
var n2 = new Filter("NAME2", FilterOperator.EQ, oName2);
var s = new Filter("STATE", FilterOperator.EQ, oState);
var c = new Filter("CITY", FilterOperator.EQ, oCity);
var cc = new Filter("BUKRS", FilterOperator.EQ, oCompanyCode);
var zip = new Filter("PSTCODE", FilterOperator.EQ, oZip);
var finalFilter = new Filter({filters:[p,n1,n2,c,s,zip,cc], and:true});
var oModel = new sap.ui.model.odata.v2.ODataModel("/sap/opu/odata/sap/ZSM_PLANTSRCH_SRV/"); sap.ui.getCore().setModel(oModel);
var oModel2 = new sap.ui.model.json.JSONModel();
oModel.read("/PLANTSRCHSet", {
filters: finalFilter,
success: function (oData, oResponse)
{ var data = oData; oModel2.setData(data); this.getView().byId("table1").setModel(oModel2, "key2"); },
error: function (oError) { //alert("error"); } });
}
答案 0 :(得分:-1)
1.View.xml
<fb:FilterGroupItem name="Name of the Property" label="Company">
<fb:control>
<Input type="Text"/>
</fb:control>
</fb:FilterGroupItem>
_search: function (oEvt) {
// All your filters of the filterbar
var aSelectionSet = oEvt.getParameter("selectionSet");
//Loop through them all
var aFilters = aSelectionSet.reduce(function (aResult, oControl) {
//Check via oControl.getValue() || oControl.getSelectedKey() || oControl.getMetadata().getName() what to do
if (oControl.getValue()) { //sap.m.Input - single filter
aResult.push(new Filter({
path: oControl.getName(),
operator: FilterOperator.EQ,
value1: oControl.getValue()
}));
} else if (oControl.getMetadata().getName() === "sap.m.MultiInput") { // sap.m.MultiInput - multiple Filter
var aTokens = oControl.getTokens();
var aTokenFilter = [];
for (var i = 0; i < aTokens.length; i++) {
aTokenFilter.push(new Filter({
path: oControl.getName(),
operator: FilterOperator.EQ,
value1: aTokens[i].getProperty("key")
}));
}
if (aTokenFilter.length > 0) {
aResult.push(new Filter({
filters: aTokenFilter,
and: false
}));
}
}
return aResult;
}, []);
if (aFilters.length > 0) {
this._filterTable(new Filter({
filters: aFilters,
and: true
}));
} else {
this._filterTable();
}
},
_filterTable: function (oFilter) {
this._oTable.getBinding("items").filter(oFilter);
}