2016-01-22 18 views
1

我對odata查詢有過濾。有沒有辦法將結果的數據存儲到另一個模型(JSON)中。我需要搜索過濾器來搜索列表中顯示的項目,而不是搜索整個odata模型。如何將OData查詢的結果數據存儲到JSON模型

updateProductsList : function(){ 
    var filters = []; 
    filters.push(new sap.ui.model.Filter("SalesOrganization", sap.ui.model.FilterOperator.EQ, this.oSalesOrganization)); 
    filters.push(new sap.ui.model.Filter("DistributionChannel", sap.ui.model.FilterOperator.EQ, this.DistributionChannel)); 
    filters.push(new sap.ui.model.Filter("ProductID", sap.ui.model.FilterOperator.Contains, this.sFilterPattern)); 
    filters.push(new sap.ui.model.Filter("CustomerNo", sap.ui.model.FilterOperator.EQ, this.oCustomerID)); 
    this.setDefaultSelection = true; 

    this.getList().bindItems("/Products", new sap.ui.xmlfragment("cus.sd.salesorder.create.view.ProductListItemTemplate",this), null,filters); 
    console.log("getPRODList0 " + this.getList().bindItems("/Products", new sap.ui.xmlfragment("cus.sd.salesorder.create.view.ProductListItemTemplate",this), null,filters)); 
var sTitle = this.getView().byId("SOC_MasterListHeaderTitle"); 
    sTitle.setText(this.oApplicationFacade.getResourceBundle().getText("PRODUCTS_CUST", [this.CustName])); 
    this.registerMasterListBind(this.getList()); 
console.log("getPRODList " + this.getList().getBinding("items").sPath); 
console.log("getPRODList2 " + this.getList().getBindingContext()); 
console.log("getPRODList3 " + this.getList().getModel()); 
}, 

回答

1

有幾種方法可以做到這一點。可能最簡單的方法是將RequestCompleted函數附加到需要模型內容副本的模型上。您可以使用Model.attachRequestCompleted函數將RequestCompleted函數附加到您的模型。

在編寫RequestCompleted處理程序時,可以使用oEvents.getParameters()來檢查響應的上下文,以檢查此請求是否對您的複製操作難以辨認。一旦檢查完畢,您可以使用Model.getProperty(「/ Products」)讀取模型並將數據複製到JSON模型中。快速注意:如果您將OData模型中的條目複製到JSON模型中,則可能是複製引用而不是副本。請注意這一點,並在必要時克隆這些條目。

+1

特別提到的「複製數組只是將引用複製到數組中,而不復制它」在這裏很重要:) – Qualiture

相關問題