Skip to Content

how to bind table created in xml view with data from a json file?

Hi,

I have a data.json file inside model folder like this:

[{ "date": "",

"from": "",

"to": "",

"hours":"",

"type":"",

"customer": "",

"project": "",

"description": "" }]

I am trying to load this into a json model like :

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

var typ= this.getView().byId("ityp").getValue();

var hrs= this.getView().byId("ihrs").getValue();

oModel.setProperty("/type",typ);

oModel.setProperty("/hours",hrs);

and setting the path in xml table:

<Table id="tstable" items="model/data.json">

<columns>

.

.

<items>

<ColumnListItem>

<cells>

<ObjectIdentifier title="{hours}"/>

<ObjectIdentifier title="{type}"/>

.

.

but neither the JSON model is fetching any data from data.json nor the table is being populated.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Oct 17, 2017 at 08:37 AM

    can you replace this line

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

    with this ?

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

    it will load the json data.

    Later on bind model to page,

    this.getView().setModel(oModel);

    and change your items binding to;

    <Table id="tstable" items="{/}">
    Add comment
    10|10000 characters needed characters exceeded

  • Oct 19, 2017 at 03:27 AM

    You can store your JSON in a variable, and for the JSON model, use the setData() method with the variable as the parameter.

    Add comment
    10|10000 characters needed characters exceeded