我有一個Ext.Panel卡片佈局嵌套在導航視圖中。我這樣做是爲了在地圖和列表之間輕鬆切換,而無需彈出,然後推入一個完全不同的視圖(基本上避免了動畫)。所以,我在navigationBar中有一個按鈕,在控制器中觸發一個動作。此初始視圖帶有一個列表,加載正常,但在視圖之間切換的控制器代碼(使用setActiveItem())不起作用。沒有錯誤信息。我發現了一些有關你需要調用show()的錯誤。雖然這有效,但它將在navigaionBar上覆蓋新的activeItem(本例中爲Map)! (見屏幕截圖)。另外,如果我只是在包裝器的配置中手動將activeItem更改爲1,則它將顯示地圖,與列表相同。Sencha Touch 2 - 導航視圖內部卡片佈局的setActiveItem問題
我包裝紙板看起來是這樣的:
Ext.define(ViewInfos.VendorWrapper.ViewName,{
extend: 'Ext.Panel',
id: ViewInfos.VendorWrapper.PanelId,
xtype: ViewInfos.VendorWrapper.Xtype,
config:
{
layout: 'card',
title: Resources.VendorsNearby,
activeItem: 0,
items: [
{
xtype: ViewInfos.VendorList.Xtype, //Initially shown, a list
},
{
xtype: ViewInfos.VendorMap.Xtype, //What I'm trying to show, a map
}
]
}
});
這裏是我的控制器代碼:
Ext.define('OrderMapper.controller.VendorWrapper', {
extend: 'Ext.app.Controller',
config: {
refs: {
vendorMap: ViewInfos.VendorMap.Xtype,
vendorList: ViewInfos.VendorList.Xtype,
vendorWrapper: ViewInfos.VendorWrapper.Xtype,
main: ViewInfos.Main.Xtype,
vendorToggleButton: (ViewInfos.Main.Xtype + ' button[action=vendorViewToggle]')
},
control: {
vendorToggleButton:{
tap: function(){
var curView = this.getVendorWrapper().getActiveItem().id;
//active view == VendorList
if(curView == 'VendorList'){
//this shows up in the console
console.log('vendorToggleButton tapped, switching to map');
this.getVendorWrapper().setActiveItem(1);
//without this line, the view doesn't even change
this.getVendorWrapper().show();
this.getVendorToggleButton().setText('List');
}
//active view == VendorMap
else if (curView == 'VendorMap'){
console.log('vendorToggleButton tapped, switching to list');
this.getVendorWrapper().setActiveItem(0);
this.getVendorToggleButton().setText('Map');
}
}
}
}
}
這裏是上this.getVendorWrapper().show()
另外,我嘗試將包裝器更改爲Carousel(而不是使用卡片佈局的普通面板),並將卡魯sel將滑動以更改列表/地圖,但setActiveItem()STILL不起作用。
順便說一句,你的問題得到解答,你需要接受點擊檢查符號正確答案的答案旁邊。這是感謝找到答案的人的一種方式。 –