I'm having trouble getting the current JSON model element associated with the RowRepeater element. With tables and lists, I would simply retrieve the current index (or indexes) and, based on these values, point to the corresponding element in my JSON model.
However, the RowRepeater element does not have a current index property. It seems to me that I should be able to directly extract the current element, and not indirectly by the current index, is there a better, single way to extract the current element?
Example code for the model:
var mydata = {
"data": [
{
"key": "67b895bf-8d89-11e3-94a7-0000005341de",
"name": "my 1st item"
},
{
"key": "7780de05-8d83-11e3-bec4-0000005341de",
"name": "my 2nd item"
}
]
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(dummydata);
sap.ui.getCore().setModel(oModel);
Sample code for RowRepeater (I want to get the current "key" when I click on the delete icon):
var oRowRepeater = new sap.ui.commons.RowRepeater();
var oRowTemplate = new sap.ui.commons.layout.MatrixLayout();
var matrixRow, matrixCell, control;
matrixRow = new sap.ui.commons.layout.MatrixLayoutRow();
control = new sap.ui.commons.TextView();
control.bindProperty("text","name");
matrixCell = new sap.ui.commons.layout.MatrixLayoutCell();
matrixCell.addContent(control);
matrixRow.addCell(matrixCell);
var icon = new sap.ui.core.Icon({
src: sap.ui.core.IconPool.getIconURI("delete"),
size: "16px",
color: "#333",
activeColor: "#BBB",
hoverColor: "#888",
width: "60px",
});
icon.attachPress(function(oEvent) {
sap.ui.commons.MessageBox.alert("TODO: Implement delete based on current/data/?/key");
});
matrixCell = new sap.ui.commons.layout.MatrixLayoutCell({ hAlign : sap.ui.commons.layout.HAlign.Right });
matrixCell.addContent(icon);
matrixRow.addCell(matrixCell);
oRowTemplate.addRow(matrixRow);
oRowRepeater.bindRows("/data", oRowTemplate);
source
share