2017-01-31 26 views
0

我正在使用SAPUI5,我有一個MasterPage和一個DetailPage,在MasterPage中我有一個List,當我在List中選擇de Item時,信息顯示在DetailPage中。如何獲取視圖的數據

在DetailPage中,我有一個PositiveAction,當我按下PositiveAction時,我需要獲取DetailPage的數據,但我不知道如何做到這一點。

我的項目的代碼按

onPoSelect : function(oEvent) { 
     var oListItem = oEvent.getParameter('listItem'); 
     var oRouter = sap.ui.core.UIComponent.getRouterFor(this); 
     oRouter.navTo("DetailPanel", { 
      invoicePath: oListItem.getBindingContext("solped").getPath().substr(1) 
     }); 

    }, 

我在DetailPanel

onInit: function(){ 
     var oRouter = sap.ui.core.UIComponent.getRouterFor(this); 
     oRouter.getRoute("DetailPanel").attachPatternMatched(this._onObjectMatched, this); 
    }, 
    _onObjectMatched: function (oEvent) { 
     this.getView().bindElement({ 
      path: "/" + oEvent.getParameter("arguments").invoicePath, 
      model: "solped" 
     }); 
    }, 

線 「oEvent.getParameter(」 參數 「)的代碼。invoicePath,」

返回此。

發票(CustomerName ='Alfreds Futterkiste',Discount = 0f,OrderID = 10702,ProductID = 3,ProductName ='Aniseed Syrup',Quantity = 6,Salesperson ='Margaret Peacock',ShipperName ='Speedy Express', UnitPrice = 10.0000M)

我有信息,但它是一個字符串,我怎樣才能在一個對象中轉換這個字符串?或者,我還可以如何訪問視圖中的信息?

視圖

enter image description here

回答

0

我假設你已經可以看到您的詳細信息視圖詳細的數據。 您通過bindElement函數將數據綁定到視圖,並在要查找「getBindingContext」函數的代碼中將其檢索回來。

你詳細控制器創建以下功能:

// this must be connected to Button -> <Button press="onPositivePress"> 
onPositivePress: function(oEvent) { 

var oBindingContext = this.getView().getBindingContext("solped"); 

// this is the path you can use to call odata service 
var sPath = oBindingContext.getPath(); 

// this is data you are looking for 
var oReqData = oBindingContext.getObject(); 

} 
+0

謝謝阿米戈,它的工作原理,謝謝您的回答。 –

0

轉換字符串對象到見下面的例子所述的圖像。

var a =「how r u」;

var b = [a];

你會得到一個在b中的對象。

0

通過將綁定路徑作爲參數傳遞給基礎數據模型的getProperty函數,可以將所有屬性作爲對象獲取。

var oModel = this.getView().getModel("solped"); 
var oProps = oModel.getProperty(oListItem.getBindingContext("solped").getPath()); 

然後,您可以訪問這些屬性

oProps.CustomerName; 
oProps.OrderID; 
...