cancel
Showing results for 
Search instead for 
Did you mean: 

Databinding with element count

Former Member
0 Kudos

Hi,

I got a list Item:

itm = new sap.m.ObjectListItem({

  title : "Ansprechpartner",

  icon:sap.ui.core.IconPool.getIconURI("employee"),

  type: "Navigation",

  unread : true,

  counter: 3,

  press: showContacts

  });

  menuList.addItem(itm);

The List Item should be bind to a model.

Instead of having hardcoded the value "3" I want do have a counter showing the elements under /customer/0/contacts

I there a syntax, how I can do a count, e.g.

counter: {contacts@count},

Thanks

Jens

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member182372
Active Contributor
0 Kudos

var actionListItem = new sap.m.ObjectListItem("action",

{

  title : "{name}",

  icon:sap.ui.core.IconPool.getIconURI("employee"),

  type: "Navigation",

  unread : true,

  counter: "{counter}"

   

});

$.each(data.list, function(i, item) {

  Object.defineProperty(data.list[i], "counter", { get : function(){

    return this.contacts.length; } } );

});

Former Member
0 Kudos

Hello Maksim,

thanks. Looks good.

The "data" element I have to extract from the oModdel with getData()?

Jens

former_member182372
Active Contributor
0 Kudos

Well, yeah, something like:

var data = { customer : [ { ... , contacts : [{}, {}, ....] }, {}, ...] };

Former Member
0 Kudos

Hi Jens,

            For this requirement you will have to implement inlinecount to the entity set contacts on the odata side. The Contact Entity Type must also have ContactsCount field to which you will set the inlinecount.

Then you can directly bind counter : "{ContactsCount}". It will show the count.

Regards,

             Pruthvi.