0

I have a controller that creates on the onInit function a model:

return Controller.extend("com.mindustry.SalesStatistics2.controller.Content", {

    onInit: function() {
      this.getOwnerComponent().setModel(oModel, "PayersSuggestion");
      .....

The question is, is the model PayersSuggestion globally defined or only on local?

And what is the difference between

this.getOwnerComponent().setModel(oModel, "PayersSuggestion");

and

this.getView().setModel(oModel, "PayersSuggestion");

When I use the second on the onInit function and for example few lines later I would call

const oPayersModel = this.getView().getModel("PayersSuggestion");  

then oPayersModel would be undefined.

softshipper
  • 32,463
  • 51
  • 192
  • 400
  • The `oPayersModel` **must be** defined when you just set the model on the same view. Please, extend your question and show us more code to analyze why `oPayersModel` is undefined in your case. – Boghyon Hoffmann Jan 24 '18 at 10:21
  • 1
    This answer might also help to understand the differences: https://stackoverflow.com/a/42251431 – Boghyon Hoffmann Apr 05 '18 at 18:55

1 Answers1

2

Assigning the model to the Component (using getOwnerCOmponent API) will be inherited by the Views as well. (But only after the current view is instantiated). This is because Component is at a higher level in the hierarchy.

Assigning to the View will be available at the view and also at the controls inside it.

krisho
  • 1,004
  • 7
  • 26