Skip to Content

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

Binding TextView with Json Model

Hi All,

I am creating an sapui5 app along with Local JSON data and I am unable to fetch the value of Purchase Order Detail in TextView i.e. unable to bind them.

At the same time i am able to bind Purchase Order with the action ListItem.

Below is my code:

//JSON Model

var data = {

  "Purchase Order List" : [

      {"Purchase Order" : "001", "Purchase Order Detail":"abc"},

      {"Purchase Order" : "002", "Purchase Order Detail":"xyz"}

  ]

};

//code

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

oModel.setData(data);

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

var oApp = new sap.m.App("mApp", { initialPage:"mainPage" });  

var oPage = new sap.m.Page(

  {

    id : "mainPage",

    title: "List of Purchase Orders",

    enableScrolling: false

  });

   

var oTextView = new sap.ui.commons.TextView("textView",

                                            {

  text: "{/Purchase Order Detail}"

});

     var detailPage = new sap.m.Page(

  {

    id : "detailPage",

    title: "Detail",

    enableScrolling: false,

    showNavButton : true,

    content:[oTextView],

    navButtonPress : function()

    {

    detailPage.unbindElement ();

    oApp.to("mainPage");

  },

  });  

var oList = new sap.m.List(

  { 

  id : "mainList",  

  inset : false,  

  visible : true,  

  

  }); 

    var actionListItem = new sap.m.ActionListItem("action",

{

  text : "{Purchase Order}",

  press : function(oControlEvent) {

  oApp.to("detailPage", this.getBindingContext());

  }

});

    oList.bindItems("/Purchase Order List", actionListItem);

    oPage.addContent(oList);

   

oApp.addPage(oPage); 

oApp.addPage(detailPage); 

oApp.placeAt("content"); 

   

Please suggest how the binding will take place between TextView and  Properties which i have created in JSON Model.

Also suggest if anything other than TextView can be used.

Regards,

Abhilasha

Former Member
replied

Adding More comments:

Example2:

JS Bin - Collaborative JavaScript Debugging

1. According to model binding, will get a data dynamically and show it in detail screen

2. Use this.getBindingContext().getModel().getProperty(this.getBindingContext().getPath()).Purchase_Order_Detail;

Thanks,

KA

0 View this answer in context

Helpful Answer

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