如何使局部变量成为全局?
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);
我想将HRER数组带到外面。当我在Ajax请求之外进行安装时,我会得到一个空数组,我将其定义为全球。我无法将进入AJAX请求的值传递给外部
在Extjs 4中,我们曾经做过:
Ext.define('A.store.SharedData', {
singleton: true,
foo: 'bar',
johnDoeAge: 42,
hrer: []
});
然后需要在要使用的任何组件中,都需要它:
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, ...];
...
}
...
});