我有两个观点.用户视图有一些文本和一个按钮.我想使用该按钮切换到第二个视图.但我不知道如何使用sencha touch 2.当我按下"UserView"(这是第一个视图)上的按钮时,我收到以下错误:
未捕获错误:SYNTAX_ERR:DOM异常12
这基本上就是我的代码现在的样子:
app.js
Ext.Loader.setConfig({ enabled: true });
Ext.setup({
viewport: {
autoMaximize: false
},
onReady: function() {
var app = new Ext.Application({
name: 'AM',
controllers: [
'Main'
]
});
}
});
Run Code Online (Sandbox Code Playgroud)
主控制器
Ext.define('AM.controller.Main', {
extend: 'Ext.app.Controller',
views : ['User'],
init: function() {
this.getUserView().create();
this.control ({
'#new': {
tap: function() {
alert('aaaa');
}
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
这两个观点:
Ext.define('AM.view.User', {
extend: 'Ext.Container',
config: {
fullscreen:true,
items: [{
xtype: 'button',
text: 'New',
id: 'new'
}
],
html: 'Testing<br />'
}
});
Run Code Online (Sandbox Code Playgroud)
第二个视图
Ext.define('AM.view.New', {
extend: 'Ext.Container',
config: {
fullscreen: true,
html: 'w00t'
}
});
Run Code Online (Sandbox Code Playgroud)
这是您的应用程序以应有的方式编写的.以下是关于我所做的更改的一些注意事项:
Ext.application而不是Ext.setup在创建MVC应用程序时调用.this.control()在控制器中使用.您只需在配置块中使用控制配置即可.views配置中定义所有视图Ext.application.init,而是在其中执行launch.这是组件应添加到视图中.应用程序/视图/ user.js的
Ext.define('AM.view.User', {
extend: 'Ext.Container',
config: {
items: [
{
xtype: 'button',
text: 'New',
id: 'new'
}
],
html: 'Testing<br />'
}
});
Run Code Online (Sandbox Code Playgroud)
应用程序/视图/ New.js
Ext.define('AM.view.New', {
extend: 'Ext.Container',
config: {
html: 'w00t'
}
});
Run Code Online (Sandbox Code Playgroud)
应用程序/控制器/ Main.js
Ext.define('AM.controller.Main', {
extend: 'Ext.app.Controller',
config: {
control: {
'#new': {
// On the tap event, call onNewTap
tap: 'onNewTap'
}
}
},
launch: function() {
// When our controller is launched, create an instance of our User view and add it to the viewport
// which has a card layout
Ext.Viewport.add(Ext.create('AM.view.User'));
},
onNewTap: function() {
// When the user taps on the button, create a new reference of our New view, and set it as the active
// item of Ext.Viewport
Ext.Viewport.setActiveItem(Ext.create('AM.view.New'));
}
});
Run Code Online (Sandbox Code Playgroud)
app.js
Ext.application({
name: 'AM',
// Include the only controller
controllers: ['Main'],
// Include all views
views: ['User', 'New'],
// Give the Ext.Viewport global instance a custom layout and animation
viewport: {
layout: {
type: 'card',
animation: {
type: 'slide',
direction: 'left',
duration: 300
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
我还建议您查看Sencha Touch API Docs上的精彩指南,以及查看Sencha论坛,因为它们非常活跃并且是一个很好的信息来源.
| 归档时间: |
|
| 查看次数: |
5534 次 |
| 最近记录: |