sapui5 - openui5: How to get current JSON model element in RowRepeater -


i'm having trouble getting current json model element bound rowrepeater element. tables , lists, retrieve current index (or indices) , based on these values, point matching element in json model.

however, rowrepeater element not have current index property. feel should able retrieve current element directly, opposed indirectly current index, there better, uniform way retrieve current element?

sample code 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 rowrepeater (i want retrieve current 'key' upon pressing delete icon):

    var orowrepeater = new sap.ui.commons.rowrepeater();      //create template control repeated , display data     var orowtemplate = new sap.ui.commons.layout.matrixlayout();      var  matrixrow, matrixcell, control;      // main row     matrixrow = new sap.ui.commons.layout.matrixlayoutrow();      //text     control = new sap.ui.commons.textview();     control.bindproperty("text","name");      //add content cell, cell row     matrixcell = new sap.ui.commons.layout.matrixlayoutcell();     matrixcell.addcontent(control);     matrixrow.addcell(matrixcell);      //delete icon     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");     });      //add content cell, cell row     matrixcell = new sap.ui.commons.layout.matrixlayoutcell({ halign : sap.ui.commons.layout.halign.right });     matrixcell.addcontent(icon);     matrixrow.addcell(matrixcell);      // add row matrix     orowtemplate.addrow(matrixrow);      //attach data rowrepeater     orowrepeater.bindrows("/data", orowtemplate); 

the following works me

icon.attachpress(function(oevent) {     sap.ui.commons.messagebox.alert(this.getbindingcontext().getproperty('name')); }); 

the selected object

var seletedrow = this.getbindingcontext().getobject() 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -