cancel
Showing results for 
Search instead for 
Did you mean: 

How to Assign Json Model property value to Id of an sapui5 element?

0 Kudos
2,238

Hi All...

I have an sapui5 application where I am trying to create a table dynamically in controller and attaching it to the view.xml.

In my controller, I am retrieving a json model and my model looks something like this.

MyModel-> Objects-> object 1{ properties..... like Id, name and so on..}

object 2{ properties..... like Id, name and so on..}

object n{properties..... like Id, name and so on..}

My Controller code for creating table dynamically is :

var oModel= this.getModel();

sap.ui.getCore().setModel(oModel);

var otable= new sap.m.Table({

mode: sap.m.ListMode.MultiSelect,

columns: [ new sap.m.Column(

{ header : new sap.m.Label({ text : "Name" }) }) ],

items: {

path: 'MyModel>/objects',

template: new sap.m.ColumnListItem({

cells: [ new sap.m.Link( 'MyModel>object/Properties/objectId' ,{

text : "{modelSource>object/Properties/name}",

enabled:true,

press: function(oEvent){ oThis.ogetMyTable(oEvent);

} }) ] }) } });

otable.setModel(new sap.ui.model.json.JSONModel(oModel),'MyModel');

otable.placeAt(this.getView().byId("p2")); },

The highlighted part is where I am trying to assign ObjectId from the model to Id of a Link element, but it is not working. I am very new to sapui5 and I googled many sites for the same ended with no proper solution.

Could anyone guide me with the syntax to achieve this would be a great help.

Thanks In Advance!!!

View Entire Topic
junwu
Active Contributor
0 Kudos

MyModel-> Objects-> object 1{ properties..... like Id, name and so on..}

object 2{ properties..... like Id, name and so on..}

object n{properties..... like Id, name and so on..}

this is not helping,

can you just give a screenshot about the model...

0 Kudos

Hi... Thanks for your reply ... Here is my Model structure.

{ "objects": [

{ "object": {

"Properties": { "objectId": "abc", "name": "1232143", },

"propertiesExtension": { "createdByFirstName": "e", "createdByLastName": "e", "lastModifiedByFirstName": "e", "lastModifiedByLastName": "e", "sapOwnerFirstName": "e", "sapOwnerLastName": "e", "sapOwnerEmail": "e" } } },

{ "object": {
"Properties": { "objectId": "fdgdg", "name": "re4t435", },

"propertiesExtension": { "createdByFirstName": "e", "createdByLastName": "e", "lastModifiedByFirstName": "e", "lastModifiedByLastName": "e", "sapOwnerFirstName": "e", "sapOwnerLastName": "e", "sapOwnerEmail": "e" } } },

{ "object": {

"Properties": { "objectId": "fgdg", "name": "345dfhgth", },

"propertiesExtension": { "createdByFirstName": "e", "createdByLastName": "e", "lastModifiedByFirstName": "e", "lastModifiedByLastName": "e", "sapOwnerFirstName": "e", "sapOwnerLastName": "e", "sapOwnerEmail": "e" } } }

],

"hasMoreItems": false

}

Each object array element will be displayed as table row values and here I am searching for the syntax to specify Properties-> ObjectId in the above model to a link element "sId" . Please find my controller code above.

Many Thanks!