当我使用Extjs 5中的一个树示例来制作我自己的树时.我将获得一个无法读取的属性'项目'为null
When I used a tree example from Extjs 5 to make my own tree. I will get a Cannot read property 'items' of null
未捕获类型错误:无法读取空的属性"items"
错误在initComponent 内部
我的错误显示,当我使用xtype:"treepanel"时,我认为initComponent 内部的错误
userName = localStorage.getItem("userName");
Ext.define('TutorialApp.view.main.Main', {
extend : 'Ext.container.Container',
requires :
[
'TutorialApp.view.main.MainController',
'TutorialApp.view.main.MainModel',
'TutorialApp.store.MainTree'
],
xtype : 'app-main',
controller: 'main',
plugins : 'viewport',
viewModel :
{
type : 'main'
},
layout : {
type : 'border'
},
items :
[
{
xtype : 'panel',
bind :
{
title: '{name} '+userName+''
},
region : 'west',
html : '<ul><li>This area is commonly used for navigation, for example, using a "tree" component.</li></ul>',
width : 250,
split : true,
collapsible : true,`enter code here`
bbar :
[
{
text : 'Button',
handler : 'onClickButton'
}
],
items : [
{
xtype : 'treepanel',
rootVisible : true,
store : 'MainTree',
initComponent: function()
{
// declare store
this.store = new TutorialApp.store.MainTree();
// declare all items
this.items = [
{
title: 'Tree'
}
];
this.callParent();
}
}
]
},
{
region : 'center',
xtype : 'tabpanel',
items :
[
{
title : 'Tab 1',
html : '<h2>Content appropriate for the current navigation.</h2>'
}
]
}
]
});
这家树店来了这是一个简单的商店
Ext.define('TutorialApp.store.MainTree', {
extend: 'Ext.data.TreeStore',
root: {
text: 'Root',
expanded: true,
children: [
{
text: 'Child 1',
leaf: true
},
{
text: 'Child 2',
leaf: true
},
{
text: 'Child 3',
expanded: true,
children: [
{
text: 'Grandchild',
leaf: true
}
]
}
]
}
});
有什么帮助吗?
我认为initComponent 内部的错误
initComponent
实际上不应该作为配置选项传递。如果您需要在initComponent
中应用自己的逻辑,则必须派生自己的类。所以,不是:
{
xtype: 'treepanel',
rootVisible: true,
store: 'MainTree',
initComponent: function() {
// declare store
this.store = new TutorialApp.store.MainTree();
// declare all items
this.items = [
{
title: 'Tree'
}
];
this.callParent();
}
}
定义自己的树面板:
Ext.define('MyTreePanel', {
extend: 'Ext.panel.Panel',
alias: 'widget.mytreepanel',
initComponent: function() {
// declare store
this.store = new TutorialApp.store.MainTree();
// declare all items
this.items = [
{
title: 'Tree'
}
];
this.callParent();
}
});
并使用其xtype:
{
xtype: 'mytreepanel',
rootVisible: true,
store: 'MainTree'
}
相关文章:
- 字符串在将其传递给另一个活动Android JavaScript时读取Null
- 用PHP读取另一个网站的源代码,并将其作为字符串提供给JavaScript
- 正在读取<p: 选择一个菜单/>在onchange回调中
- 读取一个动态填充的txt文件
- 读取一个本地文件,编码为base64,我想给用户一个将结果保存到文件的选项
- 如何在jquery中读取Section中的最后一个元素
- 读取纯javascript中的cookie(这是一个对象)
- 我希望joint.js库读取我的JSON并将其显示为一个单元格:rect和circle
- 读取一个txt文件并检查时间
- 是JavaScript(jQuery)和一个处理程序,每次从内存运行或读取
- PHP只读取动态创建的输入数组的第一个值
- 表读取最后一个变量
- 如何读取存储在图像的数据src中的URL,并在另一个img控制器的src中设置该URL onclick
- 在一个循环中读取xml文件的所有节点
- 另一个未捕获的类型错误::无法读取属性'替换'的未定义
- 读取/写入/复制一个 ArrayBuffer 到另一个具有偏移量的 ArrayBuffer
- 使用AJAX读取一个简单的文本文件.打开函数时出现拒绝访问错误
- 为什么我得到“;无法读取属性'obj2'未定义的“;在一个上,而不是在另一个上
- 我如何创建一个读取 xml 或 json 的 Chrome 扩展程序
- 相对路径-为什么我的javascript文件创建一个文件在一个位置,但试图从另一个读取它