0

I try to set a model to a view in onBeforeShow hook after I navigate to that view (using Router).

Here is my relevant view code part:

<Table items="{path:'model>/'}">
    <columns>
        <!-- columns definition here -->
    </columns>
    <items>
        <ColumnListItem>
            <cells>
                <Text text="{model>property1}"/>
                <Text text="{model>property2}"/>
                <Text text="{model>property3}"/>
                <Text text="{model>property4}"/>
                <Text text="{model>property5}"/>
            </cells>
        </ColumnListItem>
    </items>
</Table>

Then, in onBeforeShow:

var oData = sap.ui.getCore().getModel("modelSource");
this.getView().setModel(oData, "model");

"modelSource" is defined in the previous view.

When executing the model set line, I get the following error:

TypeError: e.bindList is not a function

Here is my onBeforeShow hook definition (credits to this post):

onInit: function() { 

    this.getView().addEventDelegate({ 
        onBeforeShow : jQuery.proxy(function(evt) { 
            this.onBeforeShow(evt); 
        }, this) 
    }); 
}, 

How to fix the issue?

Thanks.

Community
  • 1
  • 1
keshet
  • 1,716
  • 5
  • 27
  • 54

1 Answers1

1

I did not define the modelSource model correctly:

sap.ui.getCore().setModel(oData, "modelSource");

Defining it correctly:

sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel(oData), "modelSource");

fixed the error.

keshet
  • 1,716
  • 5
  • 27
  • 54