Reputation: 101
If I want to bind JSON to view:
XML:
<m:Input id="name" value="{/name}" enabled="false"/>
controller:
var data = {name : "name"};
var oModel = new JSONModel(data);
this.getView().setModel(oModel);
and how to bind JSON to view with spesified model name?
controller :
var data = {name : "name"};
var oModel = new JSONModel(data, "data");
this.getView().setModel(oModel);
how to code in xml? I try this but not bind.
<m:Input id="name" value="{data>/name}" enabled="false"/>
because I want to bind with 2 source json data, if i set with spesified model name, just one model bind to view.
Thanks, Bobby
Upvotes: 4
Views: 27353
Reputation: 2353
It is possible to bind n numbers of models to the view. You can specify the alias with which model is bound to the view ( or any control). You do not specify alias while creating model but at the time of setting the model to the control ( like view).
So, this is wrong:
var data = {name : "name"};
var oModel = new JSONModel(data, "data"); // Alias is not specified here
this.getView().setModel(oModel);
Correct code is :
var data = {name : "name"};
var oModel = new JSONModel(data); // Only set data here.
this.getView().setModel(oModel, "data"); // set the alias here
Similarly,
var data = {employeeName: "Rahul"};
var oModel = new JSONModel(data); // Only set data here.
this.getView().setModel(oModel, "EmployeeData"); // set the alias here
And in View,
<m:Input id="name" value="{data>/name}" enabled="false" description="{EmployeeData>/employeeName}"/>
<m:Input id="name" value="{EmployeeData>/employeeName}" enabled="false"/>
Upvotes: 13