nin*_*nse 2 javascript mobile extjs sencha-touch sencha-touch-2
我想知道如何在导航视图上挖掘后退按钮.我尝试使用onBackButtonTap,但它似乎没有工作http://www.senchafiddle.com/#8zaXf
var view = Ext.Viewport.add({
xtype: 'navigationview',
onBackButtonTap: function () {
alert('Back Button Pressed');
},
//we only give it one item by default, which will be the only item in the 'stack' when it loads
items: [
{
//items can have titles
title: 'Navigation View',
padding: 10,
//inside this first item we are going to add a button
items: [
{
xtype: 'button',
text: 'Push another view!',
handler: function() {
//when someone taps this button, it will push another view into stack
view.push({
//this one also has a title
title: 'Second View',
padding: 10,
//once again, this view has one button
items: [
{
xtype: 'button',
text: 'Pop this view!',
handler: function() {
//and when you press this button, it will pop the current view (this) out of the stack
view.pop();
}
}
]
});
Run Code Online (Sandbox Code Playgroud)
你提到的小提琴在我机器上的本地项目中运行良好.出于某种原因,它不适用于小提琴网站.尝试在本地项目上运行它.
仍然不是使用onBackButtonTapconfig,而是扩展Ext.navigation.Viewclass和override onBackButtonTap方法.这样你就可以更好地控制整个组件.你也想覆盖其他配置.这就是我用的东西 -
Ext.namespace('Ext.ux.so');
Ext.define('Ext.ux.so.CustomNav',{
extend:'Ext.navigation.View',
xtype:'customnav',
config:{
},
onBackButtonTap:function(){
this.callParent(arguments);
alert('back button pressed');
}
});
Run Code Online (Sandbox Code Playgroud)
该行将this.callParent(arguments)允许组件以默认方式运行+希望它表现的方式.如果要完全覆盖后退按钮行为,可以删除此行.尝试两种方式.
要使用此自定义组件,您可以使用 -
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
var view = Ext.create('Ext.ux.so.CustomNav', {
fullscreen: true,
items: [{
title: 'First',
items: [{
xtype: 'button',
text: 'Push a new view!',
handler: function() {
//use the push() method to push another view. It works much like
//add() or setActiveItem(). it accepts a view instance, or you can give it
//a view config.
view.push({
title: 'Second',
html: 'Second view!'
});
}
}]
}]
});
}
Run Code Online (Sandbox Code Playgroud)
试一试.这对你有用.