OPENUI5 - 如何从sap.m.Input的suggestionRows中获取所选行?

时间:2014-11-04 20:05:29

标签: javascript sapui5

我正在努力从sap.m.Input的suggestionRows中获取所选行的所有列。 我在以下链接http://jsbin.com/debavixazu/4/edit?html,console,output下的jsbin中创建了一个示例 有些机构可以教我如何从suggesttionRows获取所选行。 非常感谢提前。

此致 赤丹

1 个答案:

答案 0 :(得分:1)

请运行并检查以下代码段。基本上,您可以从所选行中获取DataModel和BindingContextPath。



<script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" id="sap-ui-bootstrap" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.m"></script>

<script>
  var oInput = new sap.m.Input('js-input', {
    value: '',
    type: sap.m.InputType.Text,
    showValueHelp: true,
    showSuggestion: true,
    placeholder: "Search ..",
    suggestionColumns: [
      new sap.m.Column({
        header: new sap.m.Label({
          text: 'Device'
        })
      }),
      new sap.m.Column({
        header: new sap.m.Label({
          text: 'Enabled'
        })
      })
    ],
    suggestionItemSelected: function(oEvent) {
      var oSelectedItem = oEvent.getParameters("selectedItem");
      //console.log(oSelectedItem);   
      var oSelectedRow = oSelectedItem.selectedRow;
      var oModel = oSelectedRow.getModel("myModel");
      var oPath = oSelectedRow.getBindingContextPath();

      alert(oModel.getProperty(oPath + "/device") + " " + oModel.getProperty(oPath + "/enabled"));

      //alert(oSelectedItem);

    }
  });

  var oModel = new sap.ui.model.json.JSONModel();
  oModel.setData({
    hardware: [{
      device: "PC",
      enabled: true
    }, {
      device: "Monitor",
      enabled: true
    }, {
      device: "Keyboard",
      enabled: false
    }, {
      device: "Mouse",
      enabled: true
    }, {
      device: "Speaker",
      enabled: false
    }, {
      device: "Scanner",
      enabled: true
    }, {
      device: "Printer",
      enabled: true
    }]
  });
  sap.ui.getCore().setModel(oModel, 'myModel');

  oColumnListItem = new sap.m.ColumnListItem({
    cells: [
      new sap.m.Label({
        text: '{myModel>device}'
      }),
      new sap.m.Label({
        text: '{myModel>enabled}'
      })
    ]
  });

  oInput.bindAggregation("suggestionRows", "myModel>/hardware", oColumnListItem);


  oInput.placeAt('content');
</script>

<body>

  <div id='content'></div>
</body>
&#13;
&#13;
&#13;