cancel
Showing results for 
Search instead for 
Did you mean: 

Binding Control to JSON Model

0 Kudos

Hi everyone. I'm trying to Bind a control to a JSON Model, but doesn't seem to be working:


// Model With Data

var lco_Model = new sap.ui.model.json.JSONModel(

{      Data: [ {      task : "done",

                         value : "10" },

      

                 {          task : "open",

                            value : "20" }      ]

});

  // Statistics Chart

  var lco_Dataset = new sap.viz.ui5.data.FlattenedDataset({

  // dimensions : [ {

  // axis : 1,

  // name : 'Task Status',

  // value : "{task}"

  // } ]

  measures : [ {

  name : 'Qty',

  value : '{value}'

  } ]

  });

  var lco_Dimension = new sap.viz.ui5.data.DimensionDefinition();

  lco_Dimension.setAxis(1);

  lco_Dimension.setName('Task Status');

  lco_Dimension.setValue(('{task}'});

  lco_Dataset.addDimension(lco_Dimension);

  lco_Dataset.bindData("/Data");

It works if I specify the value in the constructor (ie: un-commenting the lines).

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Jibran,

Is there any reason, why you're not creating the measure same like dimension definition using method .addMeasure() of flattenedDataset, try like this and check -


var oDataset = new sap.viz.ui5.data.FlattenedDataset();

var oMeasure = new sap.viz.ui5.data.MeasureDefinition({name:"Qty", value:"{value}"});

oDataset.addMeasure(oMeasure);

Check the sample here: Plunker - VizFrame, I have commented the Constructor code and use chain of methods in the controller.

Regards,

Sai Vellanki.

0 Kudos

Yes the constructor method works without any problems. But how would I bind the value at a later stage? In the output I see whatever text resides between the two brackets '{'   '}', but not the bound value. If I mention, "{value}", the actual string "{value}" reappears in the output, and not the value that is residing in JSON field value.

saivellanki
Active Contributor
0 Kudos

Jibran,

Did you check my sample? I didn't use constructor. I have done the same way that you wanted to.

Let me know if that is not the case.


Regards,

Sai Vellanki.

0 Kudos

Sorry for the late reply. I'm also using the constructor method in my example, I just want to know whether it is possible to assign the values using "SETTER" functions.


var oMeasure = new sap.viz.ui5.data.MeasureDefinition();

oMeasure.setName("Qty");

oMeasure.setValue("{value}"});

saivellanki
Active Contributor
0 Kudos

Jibran,


This statement - oMeasure.setValue("{value}"});

should be



oMeasure.bindProperty("value", "value");     // First value is the property that you want to bind, second value is your model value

Check the above statement and please let me know what was the output.


Regards,

Sai Vellanki.

0 Kudos

Yes that is absolutely correct. Where do we find the syntax for this? I searched the OpenUI5 API like crazy, and even the "Code Complete" in Eclipse doesn't pick up this method!

saivellanki
Active Contributor
0 Kudos

Property binding is available for all the controls which has properties.

Check this link for property binding syntax: Property Binding - User Interface Add-On for SAP NetWeaver - SAP Library


Regards,

Sai Vellanki.

Answers (0)