[英]Make the local variable to global in extjs
How to make local variable to global? 如何使局部变量变为全局变量?
Ext.define('A.view.Management', {
extend: 'Ext.container.Container',
requires: [
'A.store.Management',
],
border: false,
chart: null,
hrer: [],
initComponent: function () {
var me = this;
me.jobStore2 = Ext.create('O2a.store.Management');
Ext.Ajax.request({
url: utils.createUrl('api', 'ard-read'),
async: true,
callback: function(opts, success, response) {
try {
if (success) {
var output = App.decodeHttpResp(response.responseText);
const data = output.data;
let myArr = [];
data.map((date) =>
myArr = Object.keys(date).filter(key => key != 'DATE'));
me.hrer =myArr;
console.log(me.hrer);
if (output.success) {
//return output.success;
} else {
//return output.error;
}
} else {
//return 'Unknown Reason';
}
} catch (ex) {
//return ex;
}
}
});
console.log(me.hrer);
I want to take hrer array to outside. 我想将hrer阵列带到外面。 When I console.log it outside the ajax request I am getting an empty array which I have defined as globally.
当我在ajax请求之外进行console.log时,我得到的是一个已定义为全局的空数组。 I couldn't pass the values which getting inside the ajax request to outside
我无法将进入ajax请求内部的值传递给外部
In ExtJS 4, we used to do: 在ExtJS 4中,我们曾经做过:
Ext.define('A.store.SharedData', {
singleton: true,
foo: 'bar',
johnDoeAge: 42,
hrer: []
});
Then require it in whichever component you want to use and consume it like: 然后在您要使用和使用它的任何组件中要求它,例如:
Ext.define('A.view.Management', {
extend: 'Ext.container.Container',
requires: [
'A.store.Management',
'A.store.SharedData'
],
initComponent: function () {
var me = this;
A.store.SharedData.hrer = [1, 2, ...];
...
}
...
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.