1
votes

i am new to SAPUI5 and im doing some exercises about Master and Detail pages.

I have 2 views, Master.view.xml and Detail.view.xml. The Master.view.xml contains a list of employees. When the user clicks on an employee, it will navigate to the detail view. The Detail.view.xml contains the detail of the selected employee.

Each view has its corresponding controller. I've put my json model in the Master.controller.js.

How can i access the json model from the Master.controller.js to the Detail.view.xml without passing the data? Is this even possible?


@keshet

This is the List i have created in the Master page:

<List  xmlns="sap.m"
            id="masterList"
                headerText="{i18n>masterHeaderText}"
                footerText="Updated: September 4, 2015"
                items="{/employeeDetails}"
                itemPress="" >
                    <StandardListItem xmlns="sap.m" 
                        id="{empid}"
                        title="{name}"
                        description="{levelDesc}"
                        info="{cubeNo}"
                        type="Navigation"
                        tap="handleListItemPress"  />
            </List>

Now i am trying to change the id of the StandardListItem to the ID of the employee that is from the model. But an error appears saying i cant use the empid as id of the StandardListItem. How do i do this?

2
Take a look at this: linkkeshet

2 Answers

7
votes

You can declare your model globally, so all views will have access to it. To define global model:

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

To retrieve the data from the model in another view:

var oData = sap.ui.getCore().getModel().getData();

You also can give a name to your model if you want to use several global models:

var oModel = new sap.ui.model.json.JSONModel(oData);
sap.ui.getCore().setModel(oModel, "modelname");

var oData = sap.ui.getCore().getModel("modelname").getData();
1
votes

You can do this by setting your model to master. Now in detail get the view and it's corresponding model.

Master Controller-

oModel = new sap.ui.model.json.JSONModel(oData); sap.ui.getView().setModel(oModel);

Detail or anywhere you want:-

oModel = sap.ui.getView().getModel();