如何将OData查询的结果数据存储到JSON模型

时间:2016-01-22 12:39:24

标签: sapui5

我对odata查询进行了过滤。有没有办法将结果的数据存储到另一个模型(JSON)。我需要搜索过滤器来搜索列表中显示的项目,而不是搜索整个odata模型。

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 个答案:

答案 0 :(得分:1)

有几种方法可以实现这一目标。可能最简单的方法是将RequestCompleted函数附加到您的模型中,该模型会获取模型内容的副本。您可以使用Model.attachRequestCompleted函数将RequestCompleted函数附加到模型。

在编写RequestCompleted处理程序时,您可以使用oEvents.getParameters()来检查响应的上下文,以检查此请求对于您的复制操作是否难以辨认。检查完成后,您可以使用Model.getProperty(" / Products")读取模型,并将数据复制到JSON模型中。

快速说明:如果将条目从OData模型复制到JSON模型,则可能是复制引用而不是副本。请注意这一点,并在必要时克隆这些条目。