应用中只有一个NavigationView的情况:
// 处理一下android返回按钮
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown() {
var canPop = false;
var id = Ext.Viewport.getActiveItem().id;
if (id.indexOf("login") != -1) {
} else if (id.indexOf("mainview") != -1) {
var mainview = Ext.Viewport.getActiveItem();
var length = mainview.getItems().length;
if (length > 2) {
canPop = true;
}
}
if (canPop) {
console.log("canPop");
ChinaFertilizer.app.getController("MainController").pop(1);
} else {
Ext.Msg.confirm("提示", "您确定要退出应用吗?", function(e) {
if (e == "yes") {
navigator.app.exitApp();
}
}, this);
}
}
在Ext.tab.Panel下有多个NavigationView的情况:
// 处理一下android返回按钮
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown() {
var item = Ext.Viewport.getActiveItem();
var id = item.id;
if (id.indexOf("mainView") != -1) {
var mainview = Ext.Viewport.getActiveItem();
// var mainview = Ext.getCmp('moreView').getActiveItem();
var length = mainview.getActiveItem().getItems().length;
console.log("length = " + length);
if(length > 2){
if(app.viewId == 0){
app.getController("phone.MyAppControllerP").pop(1);
}else if(app.viewId == 1){
app.getController("phone.TodoControllerP").pop(1);
}else if(app.viewId == 2){
app.getController("phone.AppCenterControllerP").pop(1);
}else if(app.viewId ==3){
app.getController("phone.MoreControllerP").pop(1);
}
}else{
if (typeof WL === 'undefined') {
Ext.Msg.confirm("提示", "您确定要退出应用吗?", function(e) {
if (e == "yes") {
navigator.app.exitApp();
}
}, this);
} else {
WL.SimpleDialog.show("提示", "您确定要退出应用吗?", [ {
text : "确定",
handler : function() {
navigator.app.exitApp();
}
}, {
text : "取消",
handler : function() {
}
} ]);
}
}
}else{
if (typeof WL === 'undefined') {
Ext.Msg.confirm("提示", "您确定要退出应用吗?", function(e) {
if (e == "yes") {
navigator.app.exitApp();
}
}, this);
} else {
WL.SimpleDialog.show("提示", "您确定要退出应用吗?", [ {
text : "确定",
handler : function() {
navigator.app.exitApp();
}
}, {
text : "取消",
handler : function() {
}
} ]);
}
}