on 12-04-2014 7:58 AM
Hi guys,
I'm having a problem transferring 2 OData models to the same page. I'm not using spitapp. Let me explain
I have 3 pages.
In the first page I navigate from a list with :
handleListSelect : function (evt) {
var app = sap.ui.getCore().byId("App--app");
var context = evt.getParameter("listItem").getBindingContext();
app.to("App--orderView", context);
},
and when I get in the "Order" page, I do this:
onInit : function(evt) {
// binding model synchronisation
this.getView().addDelegate({ onBeforeShow: function(evt) {
if (this.direction != "back") {
evt.to.setModel(evt.data.oModel);
evt.to.setBindingContext(evt.data);
} //endif
} //endfunc onBeforeShow
}); //endDelegate
},
On the Order page, I have the "Add product button" that takes me to the third page.
From that page, I navigate back to the Order page using something similar to the first navigation:
onAddPress : function (oEvt) {
var aContexts = this.getView().byId("idMaterialsList").getSelectedContexts(true);
var app = sap.ui.getCore().byId("App--app");
app.to("App--orderView", aContexts);
}
But when I get back to the Order page, from the Materials page 2 things happened:
1. The data from the first oModel gets overwritten by the new data from the new oModel
2. The selected from the Materials list doesn't show up in the Order items list:
<List id ="idMaterialsList"
items ="{/Materials}"
selectionChange ="onSelectionChange"
mode ="MultiSelect"
includeItemInSelection ="true">
<!-- <items> -->
<ObjectListItem
title="{Material}"
type="Inactive"
number="11"
numberUnit="numberUnit"
press="handleListItemPress" >
<attributes>
<ObjectAttribute text="{Description}" />
</attributes>
<firstStatus>
<ObjectStatus text="3"/>
</firstStatus>
</ObjectListItem>
<!-- </items>-->
</List>
Any idea how can I improve this ?
Thank you,
Marius
you can do two things:
1) add multiple models to the global core object then you need to access the model and its data
2) you can create one model with different properties. once you create the model, then you can do this.
oModel.setData({ dataSetA: someData, dataSetB: someOtherData });
then you can access those data sets independently on the same page with the relative path
hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My model contains the service which is like this (since I'm using SMP 3.0):
with all the collections in it /Materials, /SalesOrderHeader, /SalesOrderItems, /Clients.
So in my case, when I use oModels, I already have reference to all of these (Right?).
In the first screen when I select the client for my order, I'm using the model oModel/Clients, more precisely:
<List
items="{/Clients}"
<!-- <items> -->
<ObjectListItem
title="{Name}"
type="Inactive"
</ObjectListItem>
<!-- </items>-->
</List>
and in the third screen I have something similar for the materials oModel/Materials:
<List
items ="{/Materials}" >
<!-- <items> -->
<ObjectListItem
title="{Material}"
</ObjectListItem>
<!-- </items>-->
</List>
Now in the second screen, for orders, should I use the "/SalesOrderHeader, /SalesOrderItems" colections ?
Because at the moment I just import the model that is in the "context" and go from there. I imagine that it's not the perfect way, but how do I create a oModel with only those two collections?
There is something I'm missing in the app design or logic. Even if I wirte "oModel.setData({ dataSetA: someData, dataSetB: someOtherData });" how do the elements in my Order screen know how to extract the data from the correct oModel?
Can you shade some light onto it?
Thank you,
Marius
Hi,
what about giving your second model a name? So the first one will not be overwritten ...
kind regards
Kai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, eh just let me summarize your case:
Is that all right?
Maybe you can build a small example of your app here?
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.