简体   繁体   English

SAPUI5:在片段的ViewSettingsDialog中添加新的“ ViewSettingsItem”

[英]SAPUI5: Add new “ViewSettingsItem” in into ViewSettingsDialog in a Fragment

Currently I have a fragment for sorting purpose. 目前,我有一个用于排序目的的片段。 When user click on sorting button. 当用户单击排序按钮时。 It display following screen. 显示以下画面。

在此处输入图片说明

However, what I need to to is I have to add "ViewSettingsItem" dynamically into "ViewSettingsDialog" in Fragment. 但是,我需要做的是我必须在Fragment的“ ViewSettingsDialog”中动态添加“ ViewSettingsItem”。 I have no idea how to achieve it because for fragment.xml. 我不知道如何实现它,因为存在fragment.xml。 We do not have controller. 我们没有控制器。 Where should we add the new “ViewSettingsItem” dynamically? 我们应该在哪里动态添加新的“ ViewSettingsItem”?

The following is my sample code for fragmen.xml 以下是我的fragmen.xml示例代码

<core:FragmentDefinition id="customerSortDialogFragment" xmlns:core="sap.ui.core" xmlns="sap.m">
    <ViewSettingsDialog confirm="onSortDialogConfirmed" id="sortingViewSettingsDialog">
        <sortItems>
            <ViewSettingsItem id="idCUSTOMER_ID" key="CUSTOMER_ID" selected="true" text="Customer ID"/>
            <ViewSettingsItem id="idCUSTOMER_NAME" key="CUSTOMER_NAME" text="Customer Name"/>
            <ViewSettingsItem id="idADDRESS_LINE_1" key="ADDRESS_LINE_1" text="Address Line 1"/>
            <ViewSettingsItem id="idADDRESS_LINE_2" key="ADDRESS_LINE_2" text="Address Line 2"/>
            <ViewSettingsItem id="idPRIVATE_NUMBER" key="PRIVATE_NUMBER" text="Private Number"/>
        </sortItems>
    </ViewSettingsDialog>
</core:FragmentDefinition>

Even if a fragment doesn't have a controller, you see the confirm="onSortDialogConfirmed" , that method needs to be implemented somewhere, right? 即使片段没有控制器,您confirm="onSortDialogConfirmed"看到confirm="onSortDialogConfirmed" ,该方法需要在某个地方实现,对吗? Well that is done in the controller of the view where you are calling the fragment. 好吧,这是在调用片段的视图的控制器中完成的。

In the same controller, you can get the ViewSettingsDialog instance and manipulate just like any other control. 在同一控制器中,您可以获取ViewSettingsDialog实例并像其他任何控件一样进行操作。

Check this sample of opening a dialog fragment and it's code here . 检查打开对话框片段的示例这里是代码

In your scenario you can try the following in the controller method that opens the fragment, (referring to the sample link above) 在您的方案中,您可以在打开片段的控制器方法中尝试以下操作(请参阅上面的示例链接)

//Get the dialog instance
var oDialog = sap.ui.xmlfragment(this.getView().getId(), "path.of.your.fragment", this);
// connect dialog to view (models, lifecycle)
this.getView().addDependent(oDialog);
//Create a Sort Item and add it to the dialog
var oCustomSortItem = new sap.m.ViewSettingsItem({text:"New settings item"})
oDialog.addSortItem(oCustomSortItem);
oDialog.open();

ViewSettingsDialog documentation ViewSettingsDialog文档

ViewSettingsItem documentation ViewSettingsItem文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM