我正在学习 Extjs 并尝试遵循本教程 http://www.sencha.com/learn/the-mvc-application-architecture/ 一切顺利.. 但是,当我继续“创建模型和商店”并按照教程中的说明进行操作时,然后运行它。 它给出错误:Uncaught TypeError: Cannot read property 'items' of undefined 我错过了什么吗? 谢谢
/app/controller/User.js
Ext.define('AM.controller.Users', {
extend: 'Ext.app.Controller',
stores: [
'Users'],
models: ['User'],
views: [
'user.List',
'user.Edit'],
init: function () {
this.control({
'viewport > panel': {
render: this.onPanelRendered
},
'userlist': {
itemdblclick: this.editUser
}
});
},
editUser: function (grid, record) {
var view = Ext.widget('useredit');
view.down('form').loadRecord(record);
},
onPanelRendered: function () {
console.log('panel rendered');
}
})
/app/model/User.js
Ext.define('AM.model.User', {
extend: 'Ext.data.Model',
fields: ['name', 'email']
});
/app/store/Users.js
Ext.define('AM.store.Users', {
extend: 'Ext.data.Store',
model: 'AM.model.User',
data: [
{name: 'Ed', email: 'ed@sencha.com'},
{name: 'Tommy', email: 'tommy@sencha.com'}
]
});
/app/view/user/Edit.js
Ext.define('AM.view.user.Edit', {
extend: 'Ext.window.Window',
alias : 'widget.useredit',
title : 'Edit User',
layout: 'fit',
autoShow: true,
initComponent: function() {
this.items = [
{
xtype: 'form',
items: [
{
xtype: 'textfield',
name : 'name',
fieldLabel: 'Name'
},
{
xtype: 'textfield',
name : 'email',
fieldLabel: 'Email'
}
]
}
];
this.buttons = [
{
text: 'Save',
action: 'save'
},
{
text: 'Cancel',
scope: this,
handler: this.close
}
];
this.callParent(arguments);
}
});
/app/view/user/List.js
Ext.define('AM.view.user.List',{
extend: 'Ext.grid.Panel',
alias: 'widget.userlist',
store: 'Users',
title: 'All users',
});
/myapp.js
Ext.application({
name: 'AM',
controllers : ['Users'],
appFolder: 'app',
launch: function() {
Ext.create('Ext.container.Viewport', {
layout: 'fit',
items: [
{
xtype: 'userlist',
}
]
});
}
});
/index.html
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="extjs/ext-debug.js"></script>
<script type="text/javascript" src="myapp.js"></script>
</head>
<body>
Loading apps.........
</body>
</html>
Extjs 库位于 /extjs
最佳答案
就像基于语法的注释一样,在 myapp.js 文件中的“用户列表”之后以及 List.js 文件中的“所有用户”之后都有一个额外的逗号。
此外,在该教程的评论中提到了一个类似的问题,解决方案是:
define the ‘columns’ property for the ‘List’ view
尝试将此添加到您的列表中:
columns: [
{header: 'Name', dataIndex: 'name'},
{header: 'Email', dataIndex: 'email'}
]
关于javascript - Extjs 不显示来自商店的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7670702/