这个变量可以在onContext函数中访问,但是我想将提取的ajax json结果赋值给网格的商店对象。 网格是像gride对象:{商店:“一些JSON的”}像例如访问dojojs中的这个变量时出错
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
是调用第一,然后onContext
方法调用..这个词是在功能和this
第一个可用的方法变量具有this.grid属性,this.grid属性在xhr.get()
中不可访问。此属性在xhr.get()
中更改。我想访问xhr.get()
函数内部的所有属性。因为我想我的AJAX JSON结果分配给this.grid.store
和this.grid.params.store
财产
通过这样做我得到了这个错误“k.query不是一个函数” – vaibhav