【问题标题】:how to add data to table row from the dropdown selected in a dialog box如何从对话框中选择的下拉列表中将数据添加到表行
【发布时间】:2020-02-10 06:52:50
【问题描述】:

我在对话框中的下拉菜单为:

    if (!this.pressDialog) {
        this.pressDialog = new Dialog({
  title: "Wafer",
  contentWidth: "40px",
            contentHeight: "300px",
            content: [
    new sap.m.Text({width:'100%', text: 'Component Name' }),

    new sap.m.Select({
    width: '60%', 
    items: [

    new sap.ui.core.Item("item11", {text: "Disregarded"}),

    new sap.ui.core.Item("item12", {text: "Corporation"}),

    new sap.ui.core.Item("item13", {text: "Partnership"})

    ]

    }),

    new sap.m.Text({ width:'100%',text: 'Category' }),
    new sap.m.Select({
      width: '60%',
      items: [

      new sap.ui.core.Item("item1111", {text: "Disregarded"}),

      new sap.ui.core.Item("item1234", {text: "Corporation"}),

      new sap.ui.core.Item("item1314", {text: "Partnership"})

      ]

      }),


          new sap.m.Text({width:'100%', text: 'Quantity' }),
          new sap.m.Select({
            width: '60%',
            items: [

            new sap.ui.core.Item("item15211", {text: "Disregarded"}),

            new sap.ui.core.Item("item136454", {text: "Corporation"}),

            new sap.ui.core.Item("item213754", {text: "Partnership"})

            ]

            }),

        new sap.m.Text({width:'100%', text: 'MainCategory' }),
        new sap.m.Select({
          width: '60%',
          items: [

          new sap.ui.core.Item("item11411", {text: "Disregarded"}),

          new sap.ui.core.Item("item34", {text: "Corporation"}),

          new sap.ui.core.Item("item314", {text: "Partnership"})

          ]

          })],




            beginButton: new Button({
                type: ButtonType.Emphasized,
                text: "OK",
                press: function () {
                    this.pressDialog.close();
                }.bind(this)
            }),
            endButton: new Button({
                text: "Close",
                press: function () {
                    this.pressDialog.close();
                }.bind(this)
            })
        });

        //to get access to the global model
        this.getView().addDependent(this.pressDialog);
    }

它看起来像:

如何从对话框中捕获此处的数据并将其添加到具有与每个项目相同的列的表中,

  • 组件名称,
  • 类别,
  • 数量,
  • 主要类别

我正在尝试如何从所选下拉列表的值中生成 JSON,以便可以绑定到表格

抱歉再问一个问题:how can I center the select boxes 在对话框中

感谢 TIA 的任何帮助或指导链接!

【问题讨论】:

  • 拜托,在 Stack Overflow 中专注于一个精确的问题很重要(请参阅帮助如何提问)。

标签: sapui5


【解决方案1】:

所以,我的理解是您想从选定的下拉列表 (sap.m.Select) 中创建一个 Json 模型。我们首先创建模型:

let model= {
            "componentName": "Disregarded",
            "category": "Disregarded",
            "quantity": "Disregarded",
            "mainCategory": "Disregarded",
        };
let jsonModel = new JSONModel(model);
this.getView().setModel(jsonSetting, "tableModel");

对于每个sap.m.Select,我们都有这样的东西(类别示例):

new sap.m.Select({
                        width: '60%',
                        textAlign: "Center",
                        selectedKey: "{tableModel>/category}",
                        items: [
                 new sap.ui.core.Item("item1111", {text: "Disregarded",key:"Disregarded"}),

                 new sap.ui.core.Item("item1234", {text: "Corporation",key:"Corporation"}),

                 new sap.ui.core.Item("item1314", {text: "Partnership",key:"Partnership"})
                        ]
                    }),

您必须为每个sap.ui.core.Item 添加键,例如所需的文本,而不是指定模型和选定项目selectedKey: "{tableModel>/category}" 之间的动态绑定。选择另一个项目时,模型将可见更改。

要使选择框中的文本居中,请使用textAlign: "Center",如果您想在对话框中居中,请使用sap.m.FlexBox

new sap.m.FlexBox({
         justifyContent: "Center",
         items:[
              new sap.m.Select({
                    ...
              }),
         ]
}
),

如果选择框出现包裹删除属性width:60%

现在您已经准备好模型,您可以将它与表格绑定(我想您希望在 OK 按钮的功能中使用它)。

请注意,变量model 将指定每个sap.m.Select 的初始选定键(每个人都设置为忽略)。

【讨论】:

  • 没错,我正在寻找相同的....谢谢伙计。我会参考这个并问你是否有疑问
  • 我可以知道我如何使用sap.m.FlexBox 来做同样的事情...如果我没记错的话,我怎么能把选择放在弹性框中...我想要整个选择框使中心与对话对齐
  • 感谢一吨的伙伴,它就像一个魔法!如果你有空闲时间可以看看这个Q stackoverflow.com/questions/60166309/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-15
  • 1970-01-01
  • 1970-01-01
  • 2017-09-14
  • 1970-01-01
  • 2021-10-05
  • 1970-01-01
相关资源
最近更新 更多