sencha touch界面之間的跳轉
下面是跳轉的公共類,要調用時記得把var VIEWPATH = ‘rota_persons.view.’;裡面的rota_persons改成自己app.js裡面name屬性的值
// 頁面跳轉類
var ViewUtil = {
createNew: function() {
var viewutil = {};
var viewArray = [];
var VIEWPATH = 'rota_persons.view.';
/*
* 記錄目前頁面,并進入下一頁面
* viewId: 頁面ID
* className: 頁面的userClassName
* parm: 傳遞給下一頁面的參數,為任何對象。用法: initialConfig.parm
*/
viewutil.goNext = function(viewId, className, parm) {
// 記錄頁面路徑
var currentView = Ext.Viewport.getActiveItem();
var currentViewId = currentView.getId();
var currentClassName = currentView.$className;
viewArray.push({
viewId: currentViewId,
className: currentClassName
});
// 銷毀殘留頁面(一般情況下不存在殘留)
var nextView = Ext.getCmp(viewId);
if(nextView){
nextView.destroy();
}
// 進入下一頁面
className = className || VIEWPATH + viewId;
/*if(!className) {
className = VIEWPATH + viewId;
}*/
nextView = Ext.create(className, {parm: parm});
Ext.Viewport.setActiveItem(nextView);
// Ext.Viewport.animateActiveItem(nextView,{ type: 'slide', direction: 'left' });
// Ext.Viewport.animateActiveItem(nextView,{ type: 'fade' });
//console.log(viewArray);
};
/*
* 回到已記錄的上一頁面
*/
viewutil.goLast = function() {
// 銷毀目前頁面
Ext.Viewport.getActiveItem().destroy();
// 取出上一頁面
var v = viewArray.pop();
var viewId = v.viewId;
var className = v.className;
// 進入上一頁面
var lastView = Ext.getCmp(viewId);
if(!lastView){
lastView = Ext.create(className);
}
Ext.Viewport.setActiveItem(lastView);
// Ext.Viewport.animateActiveItem(lastView,{ type: 'slide', direction: 'right' });
//console.log(viewArray);
};
/*
* 銷毀已記錄的路徑,并直接打開指定頁面
* 參數同goNext
*/
viewutil.go = function(viewId, className, parm) {
var lastView;
// 銷毀目前頁面
lastView = Ext.Viewport.getActiveItem();
if(lastView) {
lastView.destroy();
}
// 銷毀已儲存的頁面
for(var i=0; i<viewArray.length; i++) {
lastView = Ext.getCmp(viewArray[i].viewId);
if(lastView){
lastView.destroy();
}
}
viewArray = [];
// 進入指定頁面
className = className || VIEWPATH + viewId;
/*if(!className) {
className = VIEWPATH + viewId;
}*/
var nextView = Ext.getCmp(viewId);
if(!nextView) {
nextView = Ext.create(className);
}
Ext.Viewport.setActiveItem(nextView);
//console.log(viewArray);
};
return viewutil;
}
};
var viewUtil = ViewUtil.createNew();
傳回時是viewUtil.goLast();
跳轉是viewUtil.goNext(‘att_information_view’,‘Security_task.view.att_information_view’);
att_information_view要和Security_task.view.att_information_view裡面的相同,代表要跳轉的頁面。