Reputation: 777
XML
table.bindItems({
path: "/",
template: new sap.m.ColumnListItem({
cells: [
new sap.m.Text({
text: "{account_name}"
}),
new sap.m.Button({
text: "Disconnect",
name:"{account_id}",
press: [that.handleButtonPress, this]
})
]
})
});
JS
handleButtonPress: function (oEvent) {
}
Here I dynamicaly bind a json data to a table. I put one button there. When I click on button, I need to take that name value in controller. How to do this..?
Upvotes: 0
Views: 1070
Reputation: 2353
Change the the context passed to button press handler to that
instead to this
where that is referring to your controller. i.e
table.bindItems({
path: "/",
template: new sap.m.ColumnListItem({
cells: [
new sap.m.Text({
text: "{account_name}"
}),
new sap.m.Button({
text: "Disconnect",
name:"{account_id}",
press: [that.handleButtonPress, that]
})
]
})
});
and in your controller:
handleButtonPress: function (oEvent) {
console.log(this); // this is your controller.
var source = oEvent.getSource();
console.log(source) // this is your button.
var oBindingObject = source.getBindingContext().getObject();
console.log(oBindingObject.account_id);// will print the button text
}
Upvotes: 2