cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use multimodel structure?

Former Member
0 Kudos

Hello expert,

As you know I'm developing a project and right now there is a situation to break me. I have 2 different views which are using 2 different models but even their desc are different, when I go to page both of them called same models that is described last.

here is my model create codes but couldnt find how to call different field from diff. models for my tables:

View1:


    aData.clients.push({"id":mname,"parti":lname,"miktar":aname,"olcbirimi":bname,"masyeri":cname,"nedkodu":dname,"harkodu":ename});

      moModel.setData(aData);

var moModel = new sap.ui.model.json.JSONModel();

  moModel.setData(aData);

  sap.ui.getCore().setModel(moModel);

View2:


bData.clients.push({"id":mname,"parti":lname,"miktar":aname,"olcbirimi":bname,"masyeri":cname,"nedkodu":dname,"harkodu":ename});

      boModel.setData(bData);

var moModel = new sap.ui.model.json.JSONModel();

  boModel.setData(bData);

  sap.ui.getCore().setModel(boModel);

Accepted Solutions (0)

Answers (2)

Answers (2)

saivellanki
Active Contributor
0 Kudos

Hi Ogulcan,

Try like this -


view1:

aData.clients.push({"id":mname,"parti":lname,"miktar":aname,"olcbirimi":bname,"masyeri":cname,"nedkodu":dname,"harkodu":ename});

var moModel = new sap.ui.model.json.JSONModel();

moModel.setData({

  modelData: {

  }

  });

sap.ui.getCore().setModel(moModel);

sap.ui.getCore().getModel().setProperty("/modelData/moModel",aData);

view2:

bData.clients.push({"id":mname,"parti":lname,"miktar":aname,"olcbirimi":bname,"masyeri":cname,"nedkodu":dname,"harkodu":ename});

sap.ui.getCore().getModel().setProperty("/modelData/boModel",bData);

Once, you are setting a model to the core, no need to define a new model again in view 2. Just set the property to the model that you defined in the first view.

If you want to get the model that you have set, use .getProperty().

Consider, I want to get hold of bData values, I would say sap.ui.getCore().getModel().getProperty("/modelData/boModel");

Like wise, you can set multiple values in the same model and you can get hold of these values from any view.

Regards,

Sai Vellanki.

former_member182372
Active Contributor
0 Kudos

there are couple ways

first you can use named model:

sap.ui.getCore().setModel(moModel, "modelFfromView1"); 

so in this case you have to prefix declarative mappibng with modelFfromView1>


like <Text text="{modelFfromView1>/0/id}"/>


or you can store the model in the view itself


this.setModel(moModel)


or


this.getView.setModel(moModel)


in case of controller

Former Member
0 Kudos

Right now I changed my code like have 2 different models one of them is local defined model one of them is coming from SAP system when I remove model of coming from SAP system my table is working but when I add it it doesnt work and have a problem with multimodels. Couldn't find any solutions..

junwu
Active Contributor
0 Kudos

when you store the model, please give different name

Former Member
0 Kudos

onInit: function() {

      var sServiceUrl = "/sap/opu/odata/sap/ZMDYO_MOBIL_SRV/";

      var oModel = new sap.ui.model.odata.ODataModel('oModel11',sServiceUrl, true, "SAPBEREFE", "Sap123456");

      sap.ui.getCore().setModel(oModel,"mainModel");

On my controller, this model has been defined and also on my view :


var moModel = new sap.ui.model.json.JSONModel();

        moModel.setData(aData);

        sap.ui.getCore().setModel(moModel, "secondModel");

And also on my view this..


  aData.clients.push({"id":mname,"parti":lname,"miktar":aname,"olcbirimi":bname,"masyeri":cname,"nedkodu":dname,"harkodu":ename});

               moModel.setData(aData);

moModel is using on here also but when I use my code like exactly this, my table is not coming with any data.

But if I remove the code on the controller, my table is working perfectly.

No solution still:(

Regards,

Ogulcan G.

former_member182372
Active Contributor
0 Kudos

>>moModel is using on here also but when I use my code like exactly this, my table is not coming with any data.

>>But if I remove the code on the controller, my table is working perfectly.

post your table binding. i still dont really understand your problem