cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way of loading multiple models into a single view in UI5?

0 Kudos

Hello experts,

I have been trying to create a view that would load data from more than one model, one model is a created model, one is a model from somewhere else in my code.

I have them both included in the controller function, but when I try to create them, I get an error where whichever model is listed second won't load.

Is there a way around this? Appreciate your help.

function (Controller, JobHistoryModel, JSONModel, MessageToast) {...
this.getView().setModel(
new JSONModel({
isListBusy: false,
}),
"dataModel"
);
this.getView().setModel(new JobHistoryModel(), "JobHistoryModel");
ThorstenHoefer
Active Contributor
0 Kudos

Hi Callum,

it would be helpful to have a screenshot of your erroir message.

Please check the comma.

new JSONModel({
            isListBusy: false,
          })

Should this not be?

new JSONModel({
            isListBusy: false
          })
CallumRae
Explorer
0 Kudos

Error message as seen in the console, I do have a comma, I just missed it when typing the code. It will do this with either model, depending which one I put second in my controller constructor function parenthesis, so that does seem to be the issue.

Accepted Solutions (0)

Answers (1)

Answers (1)

ThorstenHoefer
Active Contributor

Hi Callum,

you need to include the namespace for the JSONModel

sap.ui.define([
...
'sap/ui/model/json/JSONModel'
]
, function(
 .... ,
  JSONModel

) { 

return ....