why can't i use these
sap.ui.getCore().setModel(oModel) and this.getView().setModel("oModel","someModel")in functions other than life cycle hooks of controller in sapui5.I am trying to bind model to the controls of my view without giving it an id. so i want to make a model and set that model to the view where i will bind.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="UTF-8">
<title>Handler Context in JavaScript Views</title>
<script id="sap-ui-bootstrap"
type="text/javascript"
src="https://sapui5.netweaver.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m"
data-sap-ui-xx-bindingSyntax="complex"
>
</script>
<script>
jQuery.sap.require("sap.m.MessageToast");
sap.ui.jsview("local.view", {
getControllerName: function() {
return "local.controller";
},
createContent: function(oController) {
var oText=new sap.m.Text();
oText.bindProperty("text","oModel>/myData");
var oInput=new sap.m.Input();
oInput.bindValue("oModel>/myData");
var oIn=new sap.m.Input();
oIn.bindValue("oModel>/myData");
var oBar=new sap.m.Bar({contentLeft:oIn,contentMiddle:oText});
var oButton=new sap.m.Button({text:"press to reset",
press:function(){
oController.resetModel();
}
});
var oPage=new sap.m.Page({headerContent:[oInput],footer:oBar,showNavButton:true,content:[oButton]});
var oShell=new sap.m.App({pages:oPage});
return oShell;
}
});
sap.ui.controller("local.controller", {
onInit:function(){
var aData={"myData":"enter!!"};
var oModel=new sap.ui.model.json.JSONModel();
oModel.setData(aData);
sap.ui.getCore().setModel(oModel,"oModel");
},
resetModel:function(){
var oModel=sap.ui.getCore().getModel("oModel");
oModel.oData.myData="Reset";
}
});
sap.ui.view({
type: sap.ui.core.mvc.ViewType.JS,
viewName: "local.view"
}).placeAt("uiArea");
</script>
</head>
<body class="sapUiBody" role="application">
<div id="uiArea"></div>
</body>
</html>
how can i update my model which is bound to other controls on button press
Is there any way to access controls in controller of my view without giving it an id?
Regards,
Ajaay