简体   繁体   中英

OPENUI5 - How to get the selected row from suggestionRows of sap.m.Input?

I am struggling to get all the columns of the selected row from the suggestionRows of sap.m.Input. I have created an example in the jsbin under following link http://jsbin.com/debavixazu/4/edit?html,console,output Could some body educate me on how to get the selected row from the suggestionRows. Many thanks in advance.

Regards, Chidan

Please run and check the following code snippet. Basically you can get the DataModel and BindingContextPath from the selected row.

 <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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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