簡體   English   中英

如何將事件(在本例中為按鈕單擊)傳遞給片段以顯示與特定行關聯的數據?

[英]How to pass an event (a button click in this case) to a fragment in order to display the data associated with the specific row?

我正在開發一個 SAPUI5 應用程序,並且我有一個從 oData 服務獲取的項目表。 我需要在一個按鈕上顯示與特定行相關的詳細信息,單擊一個片段。

使用getBindingContext()將行數據綁定到 Dialog。

查看.xml

<Button text="Show Detail" press="bindDialog"/>

詳細信息SFDialog.fragment.xml

<core:FragmentDefinition
    xmlns="sap.m"
    xmlns:l="sap.ui.layout"
    xmlns:f="sap.ui.layout.form"
    xmlns:core="sap.ui.core">
    <Dialog title="SF title">
        <f:SimpleForm 
           editable="true"
           layout="ResponsiveGridLayout"
           labelSpanL="4"
           labelSpanM="4"
           labelSpanS="12"
           adjustLabelSpan="false"
           emptySpanL="0"
           emptySpanM="0"
           emptySpanS="0"
           columnsL="1"
           columnsM="1"
           singleContainerFullSize="false" >
            <f:content>
                <Label text="Amount">
                    <layoutData>
                        <l:GridData span="L2 M3 S6"/>
                    </layoutData>
                </Label>
                <Input value="{/data/Amount}">
                    <layoutData>
                        <l:GridData span="L2 M3 S6"/>
                    </layoutData>
                </Input>
                <Label text="Quantity">
                    <layoutData>
                        <l:GridData span="L2 M3 S6"/>
                    </layoutData>
                </Label>
                <Input value="{/data/Quantity}">
                    <layoutData>
                        <l:GridData span="L2 M3 S6"/>
                    </layoutData>
                </Input>
                <Label text="Unit">
                    <layoutData>
                        <l:GridData span="L2 M3 S6"/>
                    </layoutData>
                </Label>
                <Input  value="{/data/Unit}">
                    <layoutData>
                        <l:GridData span="L2 M3 S6"/>
                    </layoutData>
                </Input>
                <Label text="Status">
                    <layoutData>
                        <l:GridData span="L2 M3 S6"/>
                    </layoutData>
                </Label>
                <Input  value="{/data/Status}">
                    <layoutData>
                        <l:GridData span="L2 M3 S6"/>
                    </layoutData>
                </Input>
            </f:content>
        </f:SimpleForm>
    </Dialog>
</core:FragmentDefinition>

controller.js

bindDialog: function(oEvent) {
  var oRowData = oEvent.getSource().getParent().getBindingContext().getObject();//get the row data
    if (!this._detailDialog) {
        this._detailDialog = sap.ui.xmlfragment("path/DetailSFDialog", this);
        this.getView().addDependent(this._detailDialog);
    }    
    var oModel = new sap.ui.model.json.JSONModel();
    oModel.setData({ "data": oRowData});
    this._detailDialog.setModel(oModel);
    this._detailDialog.open();
},

Output

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM