我想學習如何使用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