Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to Fetch data present in the JSON File and display it in the List form

Hi,

    I want to fetch the data present in the json file and display it in the list form in the view.Please help me with this.

The json file(choice.json)  i am using have the following data:

{

    "components":

     [

        {

            "FirstName": "Jack",

            "LastName": "Son"

        },

        {

            "FirstName": "John",

            "LastName": "Mathew"

        },

        {

            "FirstName": "Brett",

            "LastName": "Lee"

        }

     ]

}

and my project structure looks like this

Thanks and Regards,

Lahari

Former Member
Former Member replied

Hi Lahari,

It looks like you are using a factory function for custom list aggregation. You can try something like this,

Controller onInit function:

onInit: function() {

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

  oModel.loadData("data/choice.json");

  this.getView().setModel(oModel, "choice");

}

View createContent function:

createContent : function(oController) {

  var oList = new sap.m.List("listid", {

    mode: sap.m.ListMode.SingleSelectMaster

  });

  oList.bindAggregation(

    "items",

    "choice>/components",

    function(sId,oContext) {

      return new sap.m.StandardListItem({

        title: oContext.getProperty("FirstName") ,

        description:"ui5 is great"

      })

    }

  );

        

  return oList;

}

Regards,

Scott

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question