Monday, 2 November 2015

why sap.ui.getCore().setModel() is used in sapui5?

this is used mainly for the storing the data in page and access the data in another page.like global access.


var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(mData);
this.getView().setModel(oModel);
//set the objects here
sap.ui.getCore().setModel(oModel, "FirstData");
 sap.ui.getCore().setModel(oModel, "SecondData");



//acces in any control...like following


var globalModel_one = sap.ui.getCore().getModel("FirstData");
this.getView().byId("table").setModel(globalModel_one);

here table  is the id of the Table..

the structure should like


<Table id="table" items="{/ProductCollection}" mode="Delete" delete="odelete">
<columns>
<Column>
<Text text="First Name" />
</Column>
<Column>
<Text text="Last Name" />
</Column>

</columns>
<items>
<ColumnListItem id="list">
<cells>
<Link id="link" text="{UoM}" press="handlePress" />

</cells>
<cells>

<Text text="{UoM}" />
</cells>


</ColumnListItem>
</items>

</Table>


2 comments: