2015-09-04 20 views
1
中獲取所有值

我嘗試創建簡單的SAP FIORI應用程序,但是我在從詳細視圖中顯示的表中檢索數據時遇到問題。如何從表

我使用SAP最佳實踐模板(包括路由等)+ XML視圖創建了Master-Master-Detail應用程序。在Detail.view.xml

表定義:

<Table id="Chars" inset="false" items="{CharSet}"> 
    <columns> ... </columns> 
    <items> 
    <ColumnListItem> 
     <cells> 
     <ObjectIdentifier text="{CharNo}"/> 
     <SegmentedButton selectedButton="none" visible="{isBool}"> 
      <Button icon="sap-icon://accept" id="sbOK" text="OK"/> 
      <Button icon="sap-icon://sys-cancel" id="sbNOK" text="Not OK"/> 
     </SegmentedButton> 
     </cells> 
    </ColumnListItem> 
    </items> 
</table> 

我試圖讓顯示的數據和選擇按鈕onSubmit功能Detail.controller.js,但每個代碼的語法,我試圖用這樣的錯誤的結果:

Uncaught TypeError:oTable.getContextByIndex不是函數

唯一一個,那個工作是函數,返回行計數表:

var rowCount = this.getView().byId("Chars").getBinding("items").getLength(); 

如何從表的所有行中獲取選定的按鈕?

回答

0

一個快速的方式來獲得你的onSubmit處理這些信息可能是這樣的:

var items = this.getView().byId("Chars").getItems(); 
items.forEach(function(item){ 
    // log to the console for debugging only:   
    console.log(item.getCells()[1].getSelectedButton()); 
}); 

稍微更復雜的方法是,以反映用戶交互模型。這可讓您的模型知道所選按鈕(即狀態)並始終保持最新狀態。對於這一點,你只需要聽select事件您SegmentedButton,並相應地更新你的模型中的價值:

/** listener for select event of SegmentedButton */ 
onSelect : function(oEvent) { 
    var sId = oEvent.getParameter("id"), 
     oButton = oEvent.getParameter("button"), 
     oBindingContext = oButton.getBindingContext(), 
     sNewStatus = sId.startsWith("sbOK") ? "OK" : "NOT OK"; 

    // update model 
    oBindingContext.getModel().setProperty("status", sNewStatus, oBindingContext); 
} 
+0

不幸的是'items.forEach'產生一個錯誤:_Uncaught類型錯誤:items.forEach不是FUNCTION_ – plota

+0

@plota答案的第一行有一個小錯誤。我剛剛更新了它。請再試一次。 –

+0

謝謝,這是我需要的,但數據緩存仍然存在問題。當加載詳細視圖時,所有狀態都會正常進行,但是當我加載另一個詳細視圖時,並且不按任何上面的按鈕代碼將返回以前的值。 何時何地可以清潔? – plota