0
votes

I've tried different demo application of SAPUI5 like shoping cart, manage product. But I"m unable to solve my problem. I've two views. on home view I've set my model globally like

        var model = this.getView().getModel('product');
        var oModel = new sap.ui.model.json.JSONModel(model);
        sap.ui.getCore().setModel(oModel, "product");

and then I'm navigating to product page. where i'm accessing my product name and trying to access my specific product to bind with my current view.

    _routePatternMatched: function(oEvent) {

        var name= oEvent.getParameter("arguments").name,
        oView = this.getView(),
            sPath = "/Product('" + sId + "')";
        console.log(sPath);
        var oModel = sap.ui.getCore().getModel("product");

        var oData = oModel.getData(sPath);
        console.log(oData);
        oView.bindElement({
            path: sPath,
            events: {
                dataRequested: function() {
                    oView.setBusy(true);
                },
                dataReceived: function() {
                    oView.setBusy(false);
                }
            }
        });
        //if there is no data the model has to request new data
        if (!oData) {
            oView.setBusyIndicatorDelay(0);
            oView.getElementBinding().attachEventOnce("dataReceived", function() {
                // reset to default
                oView.setBusyIndicatorDelay(null);
                this._checkIfCourseAvailable(sPath, name);
            }.bind(this));
        }
    },
    _checkIfCourseAvailable: function(sPath) {
        var oModel = sap.ui.getCore().getModel("product");
        var oData = oModel.getData(sPath);

        // show not found page
        if (!oData) {
            this._router.getTargets().display("notFound");
        }
    },

I got the right result by filtering by id. now after giving path to var oData = oModel.getData(sPath); console.log(oData); It have the right result but i'm unable to it do not show data on view i'm trying as {pruduct>/name}

1
A better approach to setting a filter in code: var oModel = sap.ui.getCore().getModel("product"); var nameFilter = new sap.ui.model.Filter('name', 'EQ', name); oModel.read("/ActionsSet", { filters: [nameFilter] });Bernard
I've used this way.in console it give me right result but I'm unable to get data on view. var oModel = oView.getModel("product "); sPath = "/Pruduct('" + sId + "')"; var oData = oModel.getData(sPath); //here data is right.. it give me the right record. but I'm unable to access it on my view. I'm trying as {product>/name} oView.bindElement({ path: sPath, events: { dataRequested: function() { oView.setBusy(true); }, dataReceived: function() { oView.setBusy(false); } } });afaq

1 Answers

0
votes

pas model name in bindElement and then access via model name ..

 oView.bindElement({
        path: sPath,
        model:modelName,
        events: {
            dataRequested: function() {
                oView.setBusy(true);
            },
            dataReceived: function() {
                oView.setBusy(false);
            }
        }
    });

In view use {modelName>name}