2014-03-28 51 views
0

我已經定義含有(1)的圓盤傳送帶的一種形式:隱藏/刪除空轉盤卡

items: [{ 
    xtype:'carousel', 
    items:[{ 
     xtype:'fieldset' 
     items:[{ 
      xtype:'textfield', 
      name:'overview1', 
      label: 'Overview 1' 
     }] 
    },{ 
     xtype:'fieldset', 
     itemId:'details', 
     items:[{ 
      xtype:'textfield', 
      name:'detail1', 
      label: 'Detail 1' 
     }] 
    }] 
}] 

和(2)一個構造

constructor:function(record) { 
    ... 
    if(record.get("showDetails")) this.down('fieldset[itemId=details]').show() 
    else this.down('fieldset[itemId=details]').hide() 
    ... 
} 

如果非要showDetails ==假 ,該字段將隱藏到該字段不可見的位置。然而,傳送帶仍然有兩張牌,但第二個是空的。如何從傳送帶上取下卡?

回答

0

人們可以使用remove/removeAt功能擺脫面板。但是,當選項卡可能包含表單數據時,這確實需要一些工作,並且應該稍後重新插入,並且預填充選項卡被移除之前的表單數據。而且,我也希望提交表單數據。

所以我只是用一個函數來隱藏標籤:

onActiveTabChange:function(carousel, newValue, oldValue, eOpts) { 
    var items = carousel.getItems(), 
     newIndex = items.indexOf(newValue), 
     details = carousel.down('field[name=DetailsTab]').getValue(); 
    if(!details && newIndex==2) carousel.setActiveItem(0); 
    // WTF moment n° 4711: newIndex can be 1 or 2 because index 0 is the indicator; but setActiveItem takes 0 or 1... 
}, 
0

在這種情況下,可能會使用簡單的面板容器與卡布局。對於操縱旋轉木馬項目,我建議看看carousel infinite source code,有rebuildInnerIndexes方法,其中項目從列表中刪除

rebuildInnerIndexes: function(activeIndex) { 
    var indexToItem = this.innerIndexToItem, 
     idToIndex = this.innerIdToIndex, 
     items = this.innerItems.slice(), 
     ln = items.length, 
     bufferSize = this.getBufferSize(), 
     maxIndex = this.getMaxItemIndex(), 
     changedIndexes = [], 
     i, oldIndex, index, id, item; 


    if (activeIndex === undefined) { 
     this.innerIndexToItem = indexToItem = {}; 
     this.innerIdToIndex = idToIndex = {}; 

     for (i = 0; i < ln; i++) { 
      item = items[i]; 
      id = item.getId(); 
      idToIndex[id] = i; 
      indexToItem[i] = item; 
      this.fireEvent('itemindexchange', this, item, i, -1); 
     } 
    } 
    else { 
     for (i = activeIndex - bufferSize; i <= activeIndex + bufferSize; i++) { 
      if (i >= 0 && i <= maxIndex) { 
       if (indexToItem.hasOwnProperty(i)) { 
        Ext.Array.remove(items, indexToItem[i]); 
        continue; 
       } 
       changedIndexes.push(i); 
      } 
     } 

     for (i = 0,ln = changedIndexes.length; i < ln; i++) { 
      item = items[i]; 
      id = item.getId(); 
      index = changedIndexes[i]; 
      oldIndex = idToIndex[id]; 

      delete indexToItem[oldIndex]; 

      idToIndex[id] = index; 
      indexToItem[index] = item; 
      this.fireEvent('itemindexchange', this, item, index, oldIndex); 
     } 
    } 
} 

希望這有助於