Skip to Content

bind label to model length

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jul 07, 2017 at 01:29 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 05, 2017 at 08:36 PM

    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


    Add comment
    10|10000 characters needed characters exceeded