我只想简单地点击一个按钮并执行一些 ExtJS 代码进行测试,但是这个 ExtJS 代码给我错误 this.el is null
。 我需要做什么才能使此代码正常工作?
main.js:
Ext.onReady(function() {
var button = new Ext.Button('button-div', {
text: 'hello',
handler: function() {
alert('pressed');
}
});
viewport = new Ext.Viewport({
layout: 'border',
items: [ button ]
});
viewport.doLayout();
});
html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css">
<script type="text/javascript" src="ext/adapter/ext/ext-base.js">
</script>
<script type="text/javascript" src="ext/ext-all-debug.js">
</script>
<script type="text/javascript" src="js/main.js"></script>
</head>
<body>
</body>
</html>
工作代码:
感谢@Mchl 的指点,现在可以使用以下代码:
Ext.onReady(function() {
var button = new Ext.Button({
text: "Click this",
handler: function() {
alert('pressed');
}
});
var regionContent = new Ext.Panel({
region: 'center',
padding:'10',
autoScroll: true,
items: [ button ]
});
viewport = new Ext.Viewport({
layout: 'border',
items: [ regionContent ]
});
viewport.doLayout();
});
最佳答案
您正在使用 layout: 'border'
,它使您的视口(viewport)使用 Ext.layout.BorderLayout
。在此布局的文档中,您会发现此注释:
- Any container using the BorderLayout must have a child item with
region:'center'
. The child item in the center region will always be resized to fill the remaining space not used by the other regions in the layout.
关于javascript - 为什么这个 ExtJS 代码得到错误 "this.el is null"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4945811/