cancel
Showing results for 
Search instead for 
Did you mean: 

Two models in component.js

former_member424513
Discoverer
0 Kudos

Hi team,

I have declared two different model in component.js.

One is oDatamodel. I didn't name it.

And another one is a JSON model. its a named model.

The problem is, I am able to bind the unnamed model in all views.

But When I tried to get JSON model, I am getting model is undefined.

The model visibility is not there in other views except in the root view.

For example if I use,

var model = this.getView().getModel("sampleModel"); //named JSON model

in root view, I am getting the object.

But If I use the same in other controller, I am getting undefined error.

Is there any way that I could fix this?

Thanks,

Karthik R

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Karthikeyan,

Try something like this in your controller:


var oComponent = this.getOwnerComponent();

var oModel = oComponent.getModel("sampleModel");

Regards,

Sai Vellanki.

former_member424513
Discoverer
0 Kudos

Hi Sai,

It worked.. Thanks for saving my day

Thanks,

Karthik R

agentry_src
Active Contributor
0 Kudos

Please mark this Discussion with a Correct Answer (closes, but does not lock the Discussion) and Helpful Answer where appropriate. See http://scn.sap.com/community/support/blog/2013/04/03/how-to-close-a-discussion-and-why   Even if you discovered the solution without any outside contributions, it helps others to understand what the solution turned out to be. 

Do not use Assumed Answered as it confuses anyone looking for the specific answer.  If you dig into the Getting Started link (top right of each SCN page), you are only instructed to mark Helpful or Correct Answers to Discussion responses. 

Thanks, Mike (Moderator)

SAP Technology RIG

Answers (0)