Skip to Content
avatar image
Former Member

How can I use multimodel structure?

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);

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Oct 17, 2015 at 02:43 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • >>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

  • Oct 20, 2015 at 02:39 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded