我想学习如何使用Sencha触摸来建立网络应用程序。我一直在按照教程Here,我有点卡住了。下面创建了一个控制器,两个视图和一个模型(所有其他代码都是从本教程复制粘贴&)。第一种观点,索引工作很好。但是,如果我尝试访问第二个,它会弹出一个空白页面,没有任何工具栏按钮可以工作,也不会触发警报。麻烦与Sencha触摸MVC
如果我注释掉this.application.viewport.setActiveItem(this.editGyms);
这行,警报将会触发,但显然它不会呈现页面。
我看了一些其他教程,他们似乎也使用setActiveItem
成员来切换视图..我是否缺少一些东西,或者我必须以某种方式停用第一个视图来激活第二个或某些东西?
HomeController.js
Ext.regController('Home', {
//Index
index: function()
{
if (! this.indexView)
{
this.indexView = this.render({
xtype: 'HomeIndex',
});
}
this.application.viewport.setActiveItem(this.indexView);
},
editGyms: function()
{
if (! this.editGyms)
{
this.editGyms = this.render({
xtype: 'EditGymStore',
});
}
this.application.viewport.setActiveItem(this.editGyms);
Ext.Msg.alert('Test', "Edit's index action was called!");
},
});
的意见/家庭/ HomeIndexView.js
App.views.wodList = new Ext.List({
id: 'WODList',
store: 'WODStore',
disableSelection: true,
fullscreen: true,
itemTpl: '<div class="list-item-title"><b>{title}</b></div>' + '<div class="list-item-narrative">{wod}</div>'
});
App.views.HomeIndex = Ext.extend(Ext.Panel, {
items: [App.views.wodList]
});
Ext.reg('HomeIndex', App.views.HomeIndex);
的意见/家庭/ EditGymStore.js
App.views.EditGymStore = Ext.extend(Ext.Panel, {
html: 'Edit Gyms Displayed Here',
});
Ext.reg('EditGymStore', App.views.EditGymStore);
型号/ appModel.js
Ext.regModel('WOD', {
idProperty: 'id',
fields: [
{ name: 'id', type: 'int' },
{ name: 'date', type: 'date', dateFormat: 'c' },
{ name: 'title', type: 'string' },
{ name: 'wod', type: 'string' },
{ name: 'url', type: 'string' }
],
validations: [
{ type: 'presence', field: 'id' },
{ type: 'presence', field: 'title' }
]
});
Ext.regStore('WODStore', {
model: 'WOD',
sorters: [{
property: 'id',
direction: 'DESC'
}],
proxy: {
type: 'localstorage',
id: 'wod-app-localstore'
},
// REMOVE AFTER TESTING!!
data: [
{ id: 1, date: new Date(), title: '110806 - Title1', wod: '<br/><br/>Desc1</br><br/>' },
{ id: 1, date: new Date(), title: '110806 - Title1', wod: '<br/><br/>Desc2</br><br/>' }
]
});
个
viewport.js与工具栏
App.views.viewport = Ext.extend(Ext.Panel, {
fullscreen: true,
layout: 'card',
cardSwitchAnimation: 'slide',
scroll: 'vertical',
styleHtmlContent: true,
style: 'background: #d8e2ef',
dockedItems: [
{
xtype: 'toolbar',
title: 'The Daily WOD',
buttonAlign: 'right',
items: [
{
id: 'loginButton',
text: 'Login',
ui: 'action',
handler: function() {
Ext.Msg.alert('Login', "This will allow you to Login!");
}
},
{
xtype: 'spacer'
},
{
xtype: 'button',
iconMask: true,
iconCls: 'refresh',
ui: 'action',
handler: function() {
Ext.Msg.alert('Refresh', "Refresh!");
}
}]
},
],
});
感谢您的帮助!
啊,是的好点,这使得感。我确实改变了这一点,但是我仍然得到了相同的效果。 – Derek
嗯,我不知道 - 我花了一分钟,粘贴了你发布到裸机上的所有内容,并在上面做了改动后,效果很好。编辑你的帖子以显示你的新的editGyms函数,除了我只能假设它与你发布的代码不同的问题,比如不在你的html或类似的东西中包含文件。 – chrixian
是的,我感谢你的帮助和第二遍。我忽略了将视图js文件包含到index.html中。我加入了包含,现在它正常工作。谢谢你的帮助! – Derek