Search code examples
odatasapui5

How to attach data to an sap.m.StandardListItem from odata binding?


I have a list where the list items are created from odata binding with the following template:

var oItemTemplate = new sap.m.StandardListItem();
oItemTemplate .bindProperty("title", "ListModel>oLabel");
oItemTemplate .data("usefulListData","ListModel>EdmType");
oItemTemplate .setType(sap.m.ListType.Active);
oItemTemplate .addStyleClass("Draggable");
oItemTemplate .attachPress(function(){
console.log(this.data("usefulListData"));
console.log("item pressed");
});

I would like to attach some custom data to the list item, so as you can see above I did the following:

oItemTemplate .data("usefulListData","ListModel>EdmType");

now I am trying to retrieve this data upon user click on the list item, I tried the following, but it did not work

oItemTemplate .attachPress(function(oSource){
console.log(oSource.data("usefulListData"));
console.log("item pressed");
});

instead of the data value I am getting the string :

"ListModel>EdmType"
"item pressed"

could you please check what's wrong?


Solution

  • attaching the data should be done this way:

    oItemTemplate .data("usefulListData","{ListModel>EdmType}");