I am creating a list dynamically, from which I need to obtain the id of the selected item. This is an example. In Alert, the current id should be returned.
I would appreciate that instead of correcting the way of writing or something else they would give me an answer to my question.
Any ideas? Thanks
var oListData = [{id: "id-1",text:"Hello World"},
{id: "id-2",text:"Hello Universe"}];
var oListModel = new sap.ui.model.json.JSONModel(oListData);
sap.ui.getCore().setModel(oListModel);
// create the main List control
var list = new sap.m.List({
});
var oCustomItem = new sap.m.CustomListItem({
content: [
new sap.m.Text({
text: "{text}"}),
new sap.m.Button({
text: "btn",
press: function(oEvent){
alert(id-1);
}
})
],
press: function(oEvent){
alert("id-1");
}
});
list.bindAggregation("items", "/", oCustomItem);
var page = new sap.m.Page({
title: "List Page",
content : list
});
var app = new sap.m.App({
pages: [page]
}).placeAt("content");
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.m,sap.ui.layout"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-theme="sap_belize"></script>