Skip to Content
0

Getting and setting the default Model once another has been setup

Sep 20 at 01:22 PM

23

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Adam Harkus Sep 20 at 03:28 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
Rahul Gupta Sep 20 at 02:28 PM
0

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>");
Show 2 Share
10 |10000 characters needed characters left characters exceeded

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.

0

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

0