How to get the data of a view

I´m using SAPUI5, I have a MasterPage and a DetailPage, in the MasterPage I have a List and when I select de Item in the List the information is displayed in the DetailPage.

In the DetailPage I have a PositiveAction, When I press the PositiveAction I need to get the Data of the DetailPage but I don't know how to do this.

My code of the Item Press

onPoSelect : function(oEvent) {
        var oListItem = oEvent.getParameter('listItem');
        var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
        oRouter.navTo("DetailPanel", {
            invoicePath: oListItem.getBindingContext("solped").getPath().substr(1)
        });

    },

My code in the DetailPanel

onInit: function (){
        var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
        oRouter.getRoute("DetailPanel").attachPatternMatched(this._onObjectMatched, this);
    },
    _onObjectMatched: function (oEvent) {
        this.getView().bindElement({
            path: "/" + oEvent.getParameter("arguments").invoicePath,
            model: "solped"
        });
    },

The line "oEvent.getParameter("arguments").invoicePath,"

returns this.

Invoices(CustomerName='Alfreds Futterkiste',Discount=0f,OrderID=10702,ProductID=3,ProductName='Aniseed Syrup',Quantity=6,Salesperson='Margaret Peacock',ShipperName='Speedy Express',UnitPrice=10.0000M)

I have the information but it is a String, How can I convert this String in an Object? Or, how else can I access the information in the view?

The image of the View

enter image description here

Upvotes: 1

Views: 2102

Answers (3)

sachad
sachad

Reputation: 307

I assume you can already see the data of the detail in your Detail view. You binded the data to the view by bindElement function and to retrieve them back in the code you are looking for "getBindingContext" function.

Create following function in your Detail controller:

// this must be connected to Button -> <Button press="onPositivePress">
onPositivePress: function(oEvent) {

var oBindingContext = this.getView().getBindingContext("solped");

// this is the path you can use to call odata service
var sPath = oBindingContext.getPath();

// this is data you are looking for
var oReqData = oBindingContext.getObject();

}

Upvotes: 1

Stephen S
Stephen S

Reputation: 3994

You can get all the properties as an object by passing the binding path as an argument to the getProperty function of the underlying Data model.

var oModel = this.getView().getModel("solped");
var oProps = oModel.getProperty(oListItem.getBindingContext("solped").getPath());

You can then access these properties as

oProps.CustomerName;
oProps.OrderID;
...

Upvotes: 1

vivek
vivek

Reputation: 140

for converting string to object see below example.

var a = "how r u";

var b = [a];

you will get object of a in b.

Upvotes: 0

Related Questions