- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经为 Container
类实现了一个 initComponent
方法,并通过 Promise
方法加载了 items
配置。
debugging
中的事情首先转到 callParent
行,然后执行转到 Promise
方法。我必须重新加载浏览器以能够获取 Promise
响应。
我已经在 initComponent
中尝试了 then()
方法但给出了错误。我怎样才能实现这种用法?
- 带有initComponent
的容器类;
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);
}
});
- Promise 类和方法;
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);
}
});
});
}
});
最佳答案
您不应该推迟完成 initComponent
函数,直到您拥有所需的数据。您要么先获取数据,然后在所有所需信息一起实例化组件(在 Promise.then()
中执行 Ext.create()
),要么让组件获取其所需的信息并根据这些信息在运行时添加子组件。在 initComponent
上调用 callParent
之前,您真正必须知道的事情很少。
如果我是你,我不会使用 me.items =
,而是使用 me.add()
以便在运行时添加子组件,初始化后。
我为你制作了一个简单的 fiddle :https://fiddle.sencha.com/#view/editor&fiddle/2k9r
关于javascript - ExtJS:如何在 initComponent 方法中等待 Promise 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51731687/
在 ExtJS 4 中构建应用程序时我很挣扎,其中一部分是关于何时在 initComponent() 中配置某些内容以及何时不... 例如在 Sencha 自己的MVC Application Arc
我在 initComponent() 中创建了一些项目 问题是,this.items不知何故指的是类变量,而不是实例变量。 因此,当我创建两个实例时,我最终会得到两个按钮。 items: [], in
我正在使用 Sencha Architect 2。我正在尝试使用文本搜索和显示结果的表格生成通用 UI 元素。通用意味着我想将它用于几种不同类型的搜索,例如对于用户,角色或其他内容。 所以我在这个关于
我在 ExtJs 工具栏中有一个按钮,如下所示 Ext.define('Member.view.members.MembersGrid', { extend: 'Ext.grid.Panel',
当我每次看到 initComponents(); 创建 JFrame 时在我的构造函数中。它是什么?如果我删除它会发生什么? 最佳答案 initcomponents() 是 NetBeans(我猜你正
我正在使用 Java 制作 JFrame 应用程序,我正在使用应用程序设计器在我的 JFrame 中插入组件。在 Jtextarea 中,我想显示一些文本,但该文本是由我在类中编写的函数返回的。所以我
我正在扩展 Ext 3.3 中的一个窗口,该窗口在许多地方被调用,并且自身有许多扩展。此窗口有一个可配置的字段。当这个字段为空,或者不包含任何项目时,我想显示一条错误消息,而不是继续显示窗口。这就是我
我正在 NetBeans 中构建 JApplet。当应用程序最初运行时,它需要先将一些文件下载到本地 PC 上才能正常运行。一旦完成下载这些文件,就应该绘制 GUI。如何暂停 JApplet 绘制 G
我正在使用 netBeans 编辑器创建桌面应用程序,我做错了生成initComponent() 方法中与数据库连接相关的三行代码。然后我通过在 txt 编辑器中打开 .java 文件删除了这些行,但
在 extjs 中,您始终可以通过 constructor() 扩展 extjs 类。对于从 Component 派生的类,您还可以通过 initComponent() 进行扩展。 我想知道为什么这么
MainFrame.java -JFrame public MainFrame() { initComponents(); Letters pl = new Lette
可能有更好的方法来做到这一点,如果可能的话,请为我提供如何实现它的指导,但我想知道是否有一种方法,在 Tab Click 上,显式调用该容器的 initComponent 函数?即,位于该选项卡面板内
我对使用 EXTJS 有点陌生,所以我正在使用一个教程(修改它以满足我的要求),但我遇到了一个错误。这是教程代码(我无法发布我的实际代码,但它具有相同的思想,只是方法名称不同): Ext.de
我需要在 mvc 模式的 sencha 中呈现一个模板,所以在 InitComponent 上我已经声明了一些变量,但我无法在 init 函数之外访问这些变量。我做了以下尝试 Ext.define('
我正在尝试运行 this ( http://jsfiddle.net/existdissolve/dkJb9/ ) 我的 Extjs 项目中的示例。但我读过我们可以替换使用 initComponent
我已经使用 ExtJS 一段时间了,但现在正在尝试转换我的项目以正确使用他们推荐的 MVC 风格。 我有一个 View 和一个 Controller 。我正在尝试为 boxready 声明一个事件监听
我有一个像这样的面板 var filterPanel = Ext.create('Ext.panel.Panel', { bodyPadding: 5, width:
我正在使用 Ext JS4 开发一个项目。在我们的一些类中,我们在 initComponent 函数中声明函数,然后可以将其设置为控件的处理程序。我将在下面包括一个例子。忽略类中的大部分内容,关键细节
免责声明:我对 ExtJS(版本 5.01)比较陌生。我希望能联系到一些 ExtJS 专家来为我指明正确的方向:在 items 配置内指定 initComponent 方法时,我收到错误。下面的代码生
我正在使用 Ext.define() 以 ExtJS 的新 MVC 方式编写所有组件。 我有点纠结是在 initComponent() 内部定义属性,还是简单地设置它们,如 property: 42,
我是一名优秀的程序员,十分优秀!