在 Aguardientico 的回答提示下进一步研究后,我发现使用 Sass 可以做到这一点,如 here 所述,但是我不想重建 ExtJS CSS,所以我添加了一些代码在运行时执行它如下:
var body = Ext.getBody();
// Remove the x-body cls from the body element
body.removeCls("x-body");
// Add x-body cls to any existing top-level ExtJs divs
body.select('>div').each(function(el) {
if (el.hasCls("x-border-box")) {
el.addCls("x-body");
}
});
body.on("DOMNodeInserted", function(e, node) {
// Add x-body cls to top-level ExtJs divs as they are created
if (node.parentNode === body.dom) {
if (Ext.fly(node).hasCls("x-border-box")) {
Ext.fly(node).addCls("x-body");
}
}
});
这个想法是从 body 元素中删除 x-body 并将其添加回由 ExtJS 创建的任何 div 作为 body 的直接子级。因为 ExtJS 会根据需要添加新的 div,例如对于选择列表,还需要注意它们是使用 DOMNodeInserted 事件创建的。
我在我的应用程序的launch 处理程序中调用此代码,但它也可以在Ext.onReady 处理程序的开头。
编辑:
我的 ExtJS 应用程序位于一个容器中,该容器呈现给 body 元素,如下所示:
Ext.create("Ext.container.Container", {
renderTo: Ext.getBody(),
...
});
但如果您渲染到另一个 DIV,您还需要将 x-body 类显式添加到您的自定义容器中,如下所示:
Ext.create("Ext.container.Container", {
renderTo: "SomeOtherDiv",
cls: "x-body",
...
});