首页 > 解决方案 > 将项目动态添加到 SelectDialog

问题描述

我需要SelectDialog根据条件根据来自后端的 Odata 向控件添加更多项目。代码是,

 if (!this._oDialog) {
this._oDialog = new sap.m.SelectDialog({});
this._oDialog.setModel(oParentModel);
this._oDialog.bindAggregation("items", {
                            path: "/et_getSidSet",
                            template: new sap.m.StandardListItem({
                                                        title: "{Sid}"
                                                    })
                                                });


if (v === '1') {
var oItem1 = new sap.m.StandardListItem({
            title: 'PC2',
            type: 'Active'
 });

 this._oDialog.addItem(oItem1);
} else if (v === '2') {
var oItem1 = new sap.m.StandardListItem({
            title: 'AC2',
            type: 'Active'
});

this._oDialog.addItem(oItem1);
var oItem2 = new sap.m.StandardListItem({
          title: 'IC2',
          type: 'Active'
   });

this._oDialog.addItem(oItem2);
}}

问题是,当我单击 helprequest 图标时,该项目不是第一次添加。但是,它是从第二次开始添加的。我需要第一次添加该项目。

提前致谢!

标签: sapui5

解决方案


使用SAPUI5'sJSView创建由按钮按下事件触发的对话框和径向图,您可以在此处查看完整的应用程序Plunkr 示例

openDialog: function() {
  if (!this.draggableDialog) {
    this.draggableDialog = new Dialog({
      title: "Charts",
      type: "Message",
      contentWidth: "900px",
      contentHeight: "700px",
      resizable: true,
      content: [
        new RadialMicroChart({
          percentage: 75,
          total: 100,
          size: "Responsive",
          valueColor: "Critical"
        })
      ],

      beginButton: new Button({
        text: "Close",
        press: function() {
          this.draggableDialog.close();
        }.bind(this)
      })
    });
    this.getView().addDependent(this.draggableDialog);
  }
  this.draggableDialog.open();

}


推荐阅读