Sencha touch 如何在Sencha Touch V2中正确激活MVC视图
我正在运行Sencha Touch V2测试版,我正在查看最新版本 我已经按照Sencha touch 如何在Sencha Touch V2中正确激活MVC视图,sencha-touch,sencha-touch-2,Sencha Touch,Sencha Touch 2,我正在运行Sencha Touch V2测试版,我正在查看最新版本 我已经按照Ext.application的说明进行了操作,正在尝试正确地布局我的MVC应用程序。不幸的是,我不知道如何用这种方法实际加载视图 index.js Ext.application({ name: 'rpc', defaultUrl: 'home/index', controllers: ['home'], //note: define controllers here launch:
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'
});
}
});
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');
}
});
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'
}
});
homeController.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'
});
}
});
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');
}
});
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'
}
});
indexView.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'
});
}
});
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');
}
});
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'
}
});
如果您能提供任何帮助,我们将不胜感激。新版本遵循extjs4中引入的MVC概念。您应该阅读,因为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'
}]
});
}
});
最后,我的主页视图:
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.define('rpc.view.home.home'{
扩展:“Ext.Panel”,
别名:“widget.homepage”,
配置:{
html:'
},
初始化:函数(){
log(“主页的InitComponent”);
这是callParent();
}
});
alias属性用于在需要时实例化类的实例。也可以使用Ext.create方法
我希望这将帮助您开始使用Sencha Touch。Abdel的回答很好 您也可以通过配置文件来执行此操作,如以下回答所示:
这很好,似乎别名位就是它所做的。。。我说的对吗?你能解释一下“小部件”指的是什么吗?如果你使用的是特定的文件结构呢?IE:您的用户访问了,但实际文件位于。找到视图的地方有没有重写的地方?@Tom,参考文档:。。您应该能够指定您的文件夹位置