我已经实现了
initComponent
方法到
Container
等级和装载
items
通过A配置
Promise
方法。
期间的事情
debugging
先去
callParent
行,然后执行转到
许诺
方法…我必须重新加载浏览器才能获取
许诺
反应。
我试过了
then()
方法在
内部组件
但会出错。我如何才能实现这种用法?
-容器类
内部组件
;
Ext.define('MyApp.view.Bar', {
extend: 'Ext.container.Container',
xtype: 'barview',
requires: [],
controller: 'barctrl',
viewModel: {
type: 'barvm'
},
initComponent: function () {
let me = this;
let fooInfo = MyApp.FooInfoClass.getFooInfo(); //There is a debugger in FooInfoClass but miss this one
if (fooInfo) {
if (fooInfo.self) {
me.items = [
{
xtype: 'componentA'
}
];
} else if (fooInfo.reference) {
me.items = [
{
xtype: 'componentB'
}
];
} else {
me.items = [
{
xtype: 'componentC'
}
];
}
}
debugger //Firstly comes to this one then goes to Promise
me.callParent(arguments);
}
});
-承诺类别和方法;
Ext.define('MyApp.FooInfoClass', {
requires: [],
singleton: true,
endpoint: MyApp.Url(),
getFooInfo: function () {
let me = this;
let responseInfo = localStorage.getItem('foo-info');
return JSON.parse(responseInfo);
},
setFooInfo: function (foo) {
let me = this;
me.foo = JSON.stringify(foo);
localStorage.setItem(me.fooInfo, me.foo);
},
fooInfo: function () {
let me = this;
return new Ext.Promise(function (resolve, reject) {
Ext.Ajax.request({
url: me.endpoint + '/info',
success: function(response, opts) {
let obj = Ext.decode(response.responseText);
let data = obj.data[0];
debugger //Secondly comes to here!
me.foo = data;
me.setFooInfo(me.foo);
resolve(me.foo);
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response);
reject(response);
}
});
});
}
});