如何在 Sencha Touch V2 中正确激活 MVC 视图
我正在运行 Sencha Touch V2 beta,并且正在查看最新的最新文档 。
我已按照 Ext.application
说明进行操作,并尝试正确布局我的 MVC 应用程序。不幸的是,我无法弄清楚如何使用这种方法实际加载视图。
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'
}
});
如果您能提供任何帮助,我们将不胜感激。
I'm running Sencha Touch V2 beta and I'm looking at the most recent documentation.
I've followed the Ext.application
instructions and am trying to properly lay out my MVC application. Unfortunately I can't figure out how to actually load up a View with this approach.
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'
}
});
Any help you might be able to offer would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
新版本遵循 ExtJS 4 中引入的 MVC 概念。您应该阅读 架构指南,因为 Sencha Touch 将遵循相同的架构。这是我的文件夹结构:
在开发应用程序期间,您应该在 html 中使用 sencha-touch-all-debug-w-comments.js。这有助于调试您的应用程序。
这是应用程序类:
注意,我如何使用别名(xtype:'homepage')包含主页视图。
这是控制器:
最后是我的主页视图:
别名属性用于在需要时实例化类的实例。您还可以使用 Ext.create 方法。
我希望这能帮助您开始使用 Sencha Touch。
The new release follows MVC concepts introduced in ExtJS 4. You should read Architecture guide because Sencha Touch will be following the same arch.Here is my folder structure:
During development of your application, you should make use of sencha-touch-all-debug-w-comments.js in your html. This helps in debugging your application.
Here is the application class:
Note, how I have included the homepage view using the alias (xtype: 'homepage').
Here is the controller:
And finally, my Homepage view:
The alias property is used to instantiate instance of the class when needed. You could also use the Ext.create method.
I hope this will help you get started with Sencha Touch.
阿卜杜勒的回答很好。
您也可以通过配置文件来完成此操作,如本答案所示:
Sencha Touch 2.0 MVC 教程
Great answer by Abdel.
You can also do it though profiles, as demonstrated in this answer:
Sencha Touch 2.0 MVC tutorial