Skip to Content

How to read the odata result in sapui5

Dear Experts,

I am new to the XML Views , and stuck in one place.

Currently I am doing an Master Details Fiori Application and binding the Header data to the list of the master view.

the data is coming correctly in my master View.

Now i have a requirement that i have to read the odata result in one of the json model , in the master controller but i am not getting how to get it.

In the JS view , we use to set the json model using the code

oJSONDetailModel = new sap.ui.model.json.JSONModel();

oJSONDetailModel.setData({

modelDataDetail : oJSONModel.oData.modelData[0]

});

But not getting how to do it in XML Views.Please help.

Regards,

Vikash

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Dec 08, 2015 at 01:54 PM

    Hi Vikasha,

    1.Here is the code that I am using in onInit method.

    eg:

    var sURI = "https://cors-anywhere.herokuapp.com/http://services.odata.org/V3/Northwind/Northwind.svc/";

    var oView = this.getView();

    var oDataModel = new sap.ui.model.odata.ODataModel(sURI);

    oView.setModel(oDataModel);


    2. Then create a new controls in view.

    3. Bind the elements from odata to view

    eg:

    new sap.m.Input({

    value : "{/Employees/0/Title}"

    })

    Hope this will helpful for your requirement.

    Regards,

    Karthik A

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Naren,

      Please find out my code :

      mvc:View controllerName="indent.view.Master" xmlns:core="sap.ui.core" xmlns:footerbar="sap.ushell.ui.footerbar" xmlns:mvc="sap.ui.core.mvc"

      xmlns="sap.m">

      <Page id="masterPage" title="{i18n>masterTitle}">

      <subHeader id="masterSubHeader">

      <Bar id="searchBar">

      <contentMiddle>

      <SearchField id="searchField" placeholder="{i18n>masterSearchPlaceholder}" liveChange="onSearch" showRefreshButton="{False}"

      tooltip="{i18n>masterSearchTooltip}" width="100%"></SearchField>

      </contentMiddle>

      </Bar>

      </subHeader>

      <content>

      <List growing="true" growingScrollToLoad="true" id="list" items="{/OrderHeaderSet}" mode="{device>/listMode}"

      noDataText="{i18n>masterListNoDataText}" select="onSelect">

      <items id="masterList">

      <ObjectListItem counter="0" id="mainListItem" markFavorite="false" markFlagged="false" number="{Status}" numberUnit="" press="onSelect"

      showMarkers="false" title="{Orderid}" type="{device>/listItemType}">

      <core:ExtensionPoint name="extListItemInfo"/>

      </ObjectListItem>

      </items>

      </List>

      </content>

      <footer id="masterFooter">

      <Toolbar id="masterToolbar">

      <content>

      <footerbar:SettingsButton icon="sap-icon://action-settings" id="settingsButton" tooltip="Help"></footerbar:SettingsButton>

      </content>

      </Toolbar>

      </footer>

      </Page>

      </mvc:View>

      Here you can see in my view i have binded the item with the orderheaderset which is called when the view is called initially.

      The service url has been declared in component.js and the global model is oModel which has been set in my component.js.

      Now in my controller i want to use the result of this odata result which i will be passing to json model so i can achieve the client side filteration for the search bar.

      But i am not geeting the point how to capture the odata result in my onsearch () controller.

      Regards,

      Vikash

  • author's profile photo Former Member
    Former Member
    Posted on Dec 08, 2015 at 02:12 PM

    Hi Vikash,

    You have to use oJSONModel.read().

    oJSONDetailModel = new sap.ui.model.json.JSONModel();

    oJSONModel.read(path,null,null,false,function(oData,oResponse){

    oJSONDetailModel.setData(oData);

    },

    function(){

    console.log('Read failed');

    });

    Regards,
    Naren L Naik

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Karthik Arjun

      HI Karthik,

      yes it is correct. JSON model is a client side model and it doesn't have read method.

      I had assumed that oJSONModel is a variable which looked something like this

      oJSONModel=new sap.ui.model.odata.ODataModel(path);

      SInce Vikash had posted he was setting the odata model initially and then trying to get the result.

      Hope that made sense.

      Regards,

      Naren

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.