Skip to Content

Getting and setting the default Model once another has been setup

My issue is that I have a default model specified in my manifest.json file as "".

However, I'm also setting up a view model in my controller.

var oModel = new JSONModel({

questions: [{ order: 1,

title: "",

criteria: "", }]

});

this.getView().setModel(oModel);

How do I restore set the view model back to the default model? Is it simply a case of

this.getView().setModel("");

I'm asking because the default model is the service that contains all my read/writes.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Sep 20, 2017 at 03:28 PM

    That's great, but if I assign a name to the view model, it's no longer bound to the view.

    I'm also using context here.

    var oModel = new JSONModel({ questions: [{ order: 1, title: "", criteria: "", category: "", competency: "", points: "", naAvailable: true, naDescription: "", commentsMandatory: false }] });

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

    var oContext = oModel.createBindingContext("/questions/0/");

    this.getView().setBindingContext(oContext);

    e.g.

    <sap.ui.layout.form:FormContainer title="Question {order}" id="__container1">

    i've tried {/viewmodel>oder} , {/viewmodel>/order} too, the view is just not displaying the order.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 20, 2017 at 02:28 PM

    Hi Adam,

    You should use only one unnamed model in your app. If you want to set another model to your view, then set it as named model:

    this.getView().setModel(oModel, "<model_name>");

    you can get this model as:

    this.getView().getModel("<model_name>");
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Please do the binding as below:

      var oModel = new JSONModel({ questions: [{ order: 1, title: "", criteria: "", category: "", competency: "", points: "", naAvailable: true, naDescription: "", commentsMandatory: false }] });
      
      this.getView().setModel(oModel, "viewmodel") ;
      
      this.getView().bindElement({
      		path: "/questions/0",
      		model: "viewmodel"
      	});
      
      

      And in the view do the binding as:

      <sap.ui.layout.form:FormContainer title="Question {viewmodel>order}" id="__container1">

      Regards,

      Rahul