Skip to Content
0

bind label to model length

Jul 05, 2017 at 06:20 PM

36

avatar image

Hi

I am trying to bind a label to length of model defined in component.js. I can get the length in component, but when I try to map the same inside view it returns undefined. I have binded table to that model and am able to get data inside table.

Here is my code in component.js

var oModel = new sap.ui.model.json.JSONModel("model/data.json");

var datacount ;

oModel.attachRequestCompleted(function() {

// console.log(this.getData().length);

datacount = this.getData().length; //I am able to get length here

oModel.setData({

struct : this.getData(),

number: datacount, });

});

this.setModel(oModel, "MyJsonData");

Inside view:

oTable.bindRows("MyJsonData>/struct/");

var lbl = new sap.ui.commons.Label({text: "{MyJsonData>/number}"});

The label is not returning anything?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Madhusudhan S Jul 05, 2017 at 08:36 PM
0

Hi Justin,

Please discard the earlier one.

Updating the suggestions below:

Did you check in debugger after the below statement whether you are getting the value ?

oModel.setData({
struct : this.getData(),
number: datacount, });
});

One way - Assign id (lbl_length) to the label 'lbl' in declaration and set the value with below statement in relevant function in the control

that.getView().byId("lbl_length").setText(datacount);

Regards

Madhu


Show 1 Share
10 |10000 characters needed characters left characters exceeded

how will setting sizelimit help?

0
VIPLOVE KHUSHALANI Jul 07, 2017 at 01:29 PM
0

Hi ,

just try without / before number : var lbl = new sap.ui.commons.Label({text: "{MyJsonData>number}"});

Are you getting the row in table ??

thanks

Viplove

Share
10 |10000 characters needed characters left characters exceeded