Hi, i wanto to create a global variable but just in my controller so i don't have to create my variables again in other function
this is my code:
onInit : function() {
},
onBuscar : function() {
var oData = new JSONModel;
oData.rut = this.byId("irut").getValue();
oData.nombres = this.byId("iNombres").getValue();
oData.apellidos = this.byId("iApellidos").getValue();
oData.calle = this.byId("iDir1").getValue();
oData.numero = this.byId("iDir2").getValue();
oData.casa = this.byId("iDir3").getValue();
oData.comuna = this.byId("iDir4").getValue();
oData.tlfFijo = this.byId("iTlf1").getValue();
oData.tlfMovil = this.byId("iTlf2").getValue();
oData.mail = this.byId("iMail").getValue();
oData.pais = this.byId("iPais").getValue();
MessageToast.show(oData.rut);
},
onModif : function() {
},
onCrear : function() {
}
i tried to create in the oninit function but get an error of undefined variable i tried like this
onInit : function() {
this.oData = new JSONModel;
oData.rut = this.byId("irut").getValue;
},
onBuscar : function() {MessageToast.show(oData.rut);
}
any suggestion? thanks!
UPDATE 1
i tried this but when i print my values are empty :/ unless that my inputs are editable false
onInit : function() {
$.oData = new JSONModel;
$.oData.rut = this.byId("irut").getValue();
$.oData.nombres = this.byId("iNombres").getValue();
$.oData.apellidos = this.byId("iApellidos").getValue();
$.oData.calle = this.byId("iDir1").getValue();
$.oData.numero = this.byId("iDir2").getValue();
$.oData.casa = this.byId("iDir3").getValue();
$.oData.comuna = this.byId("iDir4").getValue();
$.oData.tlfFijo = this.byId("iTlf1").getValue();
$.oData.tlfMovil = this.byId("iTlf2").getValue();
$.oData.mail = this.byId("iMail").getValue();
$.oData.pais = this.byId("iPais").getValue();
},
onBuscar : function() {
MessageToast.show($.oData.rut);
},