我正在运行 Sencha Touch V2 beta,我正在查看最多 recent documentation .
我已按照 Ext.application
说明进行操作,并正在尝试正确布置我的 MVC 应用程序。不幸的是,我无法弄清楚如何使用这种方法实际加载 View 。
index.js
Ext.application({
name: 'rpc',
defaultUrl: 'home/index',
controllers: ['home'], //note: define controllers here
launch: function () {
console.log('Ext.application ~ launch'),
Ext.create('Ext.TabPanel', {
id: 'rpc-rootPanel',
fullscreen: true,
tabBarPosition: 'bottom',
items: [{
title: 'Home',
iconCls: 'home'
}]
});
Ext.create('Ext.viewport.Viewport', {
id:'rpc-rootPanel',
fullscreen: true,
layout: 'card',
cardSwitchAnimation: 'slide'
});
}
});
homeController.js
Ext.define('rpc.controller.home', {
extend: 'Ext.app.Controller',
views: ['home.index'],
stores: [],
refs: [],
init: function () {
console.log('rpc.controller.home ~ init');
},
index: function () {
console.log('rpc.controller.home ~ index');
}
});
indexView.js
Ext.define('rpc.view.home.index', {
extend: 'Ext.Panel',
id: 'rpc-view-home-index',
config: {
fullscreen: true,
layout: 'vbox',
items: [{
xtype: 'button',
text: 'Videos',
handler: function () {
}
}],
html:'test'
}
});
如果您能提供任何帮助,我们将不胜感激。
最佳答案
新版本遵循 ExtJS 4 中引入的 MVC 概念。您应该阅读 Architecture guide因为 Sencha Touch 将遵循相同的架构。这是我的文件夹结构:
在您的应用程序开发期间,您应该在您的 html 中使用 sencha-touch-all-debug-w-comments.js。这有助于调试您的应用程序。
这是应用程序类:
Ext.Loader.setConfig({enabled: true});
Ext.application({
name: 'rpc',
appFolder: 'app',
controllers: ['Home'],
launch: function () {
Ext.create('Ext.tab.Panel',{
fullscreen: true,
tabBarPosition: 'bottom',
items:[{
title: 'Home',
iconCls: 'home',
html: '<img src="http://staging.sencha.com/img/sencha.png" />'
},{
title: 'Compose',
iconCls: 'compose',
xtype: 'homepage'
}]
});
}
});
请注意,我是如何使用别名 (xtype: 'homepage') 包含主页 View 的。
这是 Controller :
Ext.define('rpc.controller.Home', {
extend: 'Ext.app.Controller',
views: ['home.HomePage'],
init: function() {
console.log('Home controller init method...');
}
});
最后,我的主页 View :
Ext.define('rpc.view.home.HomePage', {
extend: 'Ext.Panel',
alias: 'widget.homepage',
config: {
html: '<img src="http://staging.sencha.com/img/sencha.png" />'
},
initialize: function() {
console.log("InitComponent for homepage");
this.callParent();
}
});
别名属性用于在需要时实例化类的实例。您也可以使用 Ext.create 方法。
我希望这能帮助您开始使用 Sencha Touch。
关于sencha-touch - 如何在 Sencha Touch V2 中正确激活 MVC View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7815905/