Skip to Content
author's profile photo Former Member
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 a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on 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 a comment
    10|10000 characters needed characters exceeded

  • Posted on 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 a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.