this variable is accessible in the onContext function but I want to assign fetched ajax json result to grid's store object. grid is the object like gride:{store:"some-Json"} like example
define([
"dojo/_base/declare",
"dojo/when",
"aps/_View",
"aps/xhr"
], function(
declare,
when,
_View,
xhr
) {
var page, grid, self, contextId,myResult,samp;
return declare(_View, {
init: function() {
self = this;
return ["aps/Grid", {
id: "srv_grid",
selectionMode: "multiple",
columns: [{
field: "id",
name: "Id"
}]
},
];
}, // End of Init
onContext: function(context) {
this.grid = this.byId("srv_grid"); //working
xhr.get("/aps/2/resources/" + aps.context.vars.device.aps.id + "/getresource").
then(function(data){
myResult=data;
this.grid.params.store=data; //got error here this.grid is undefined
this.grid.store=data; //got error here this.grid is undefined
}
),
this.grid.refresh();
},
}); // End of Declare
}); // End of Define
init
is the first method that calls first, then onContext
method call.. this word is available in that function and this
variable has this.grid property that this.grid property is not accessible in xhr.get()
.Properties of this are changed in xhr.get()
. I want to access all the properties of this inside xhr.get()
function. Because I want to assign my ajax json result to this.grid.store
and this.grid.params.store
property
You have to use the dojo/_base/lang
->
hitch function , to set the scope in wich your function will be executed .In your case the
this.grid.params...
referes to the then(xhr) so it'll return an undefined errorSo you have to execute you function in the scope of the module as below :
after important
dojo/_base/lang -> lang