Hi,
I have been playing around a bit with the MVC structure for SAPUI5 projects and have come a bit stuck! I am hoping someone can help me out. It seems like a really stupid question so my apologies upfront but I can't work out what's going on so am hoping someone else can see what I am doing wrong.
Here is the scenario:
sap.ui.jsview("mvc101.view1", { getControllerName : function() { return "mvc101.view1"; }, createContent : function(oController) { var oTextView1 = new sap.ui.commons.TextView("tView1"); oTextView1.setText("Set in View"); return oTextView1; }});
onInit: function() { this.byId("tView1").setText("Set in Controller"); },
But when I run and debug this I get an error in the console saying that this.byId("tView1") is undefined:
However when I use firebug I can see tView1 in the content aggregation of the View:
Help... What am I doing wrong here? Can anyone see my mistake?
Thanks,
Simon
Update: When I use a JSON view type as follows it works fine (no undefined errors) to access the TextView using the this.byId() method:
View2:
{ "Type":"sap.ui.core.mvc.JSONView", "controllerName":"mvc101.view2", "content": [{ "Type" : "sap.ui.commons.TextView", "id" : "tView2", "text" : "Set in View2" }]}
And the onInit method of the Controller:
onInit: function() { this.byId("tView2").setText("Set in Controller2"); }
😕