0

I am using sap.m.List to display some data. The data is coming from the JSON Model, it also has data. But somehow the binding is not working and data is not displayed in the List view. Even there is no error.

purchaseHistory.view.xml

    <mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
    controllerName="novigoapplications.SuperMarket.controller.purchaseHistory" xmlns:html="http://www.w3.org/1999/xhtml">
    <App>
        <pages>
            <Page title="Title">
                <content>
                    <List headerText="Purchase History"  width="60%" items="{ path: 'purchaseHistoryData>/Result' }" id="history">
                        <items>
                            <StandardListItem title="{purchaseHistoryData>PurchaseId}"></StandardListItem>
                        </items>
                    </List>
                </content>
            </Page>
        </pages>
    </App>
</mvc:View>

purchaseHistory.controller.js

sap.ui.define([
    "sap/ui/core/mvc/Controller"
], function (Controller) {
    "use strict";


    return Controller.extend("novigoapplications.SuperMarket.controller.purchaseHistory", {

        onInit: function () {
            var oModel = new sap.ui.model.odata.v2.ODataModel("/sap/opu/odata/sap/ZGW_UI5_SUPER_MARKET_SRV");
            sap.ui.getCore().setModel(oModel, "purchaseHistory");
            var model = sap.ui.getCore().getModel("purchaseHistory");
            model.setHeaders({
                "X-Requested-With": "X"
            });
            var readURL = "/CustomerSet('" + window.custid + "')/CusttopurNav";
            model.read(readURL, {
                success: function (oData, oResponse) {
                    var purchaseHistoryData = new sap.ui.model.json.JSONModel({
                        "Result": oData.results
                    });
                    sap.ui.getCore().setModel(purchaseHistoryData, "purchaseHistoryData");
                }
            });
        }
    });
});
Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Badhusha
  • 195
  • 2
  • 20
  • Isn't that purchaseHistoryData>/PurchaseId ? Please check if this works – KcH May 10 '20 at 09:17
  • @Codenewbie No still same problem, data is not displaying – Badhusha May 10 '20 at 09:24
  • 2
    Can you try `this.getView().setModel()` instead of `sap.ui.getCore().setModel()`? To get access to the outer `this` in your success callback you can store it in an extra variable before doing the read, e.g. `var that = this`. Then do `that.getView().setModel()` in your callback. – Marc May 11 '20 at 07:18
  • Does this answer your question? [Can't bind property from model to control on XML view](https://stackoverflow.com/questions/46894283/cant-bind-property-from-model-to-control-on-xml-view) – Boghyon Hoffmann Aug 20 '20 at 06:39

0 Answers0