2011-05-31 38 views
2

煎茶觸摸,我宣佈一個像這樣的旋轉木馬:添加元素爲輪轉煎茶

ajaxNav = new Ext.Panel({  
    scroll: 'vertical', 
    cls: 'card1 demo-data', 
    styleHtmlContent: true, 
    layout: { 
     type: 'vbox', 
     align: 'stretch' 
    }, 
    defaults: { 
     flex: 1 
    }, 
    items: [{ 
     xtype: 'carousel', 
     items: [{ 
      id:'tab-1', 
      html: '', 
      cls: 'card card1' 
     }, 
     { 
      id:'tab-2', 
      html: '<p>Clicking on either side of the indicators below</p>', 
      cls: 'card card2' 
     }, 
     { 
      id:'tab-3', 
      html: 'Card #3', 
      cls: 'card card3' 
     }] 
    }] 
}); 

有誰知道如何dinamycally添加元素?

回答

6

我給你寫一個簡單的例子,告訴你如何在現有的Ext.Carousel元素中添加一個新面板。

Ext.setup({ 

onReady: function() { 

    var ajaxNav = new Ext.Carousel({  
     fullscreen: true, 
     dockedItems: { 
      xtype: 'toolbar', 
      title: 'Demo', 
      items: [{ 
       xtype: 'button', 
       ui: 'action', 
       text: 'Add', 
       handler: function(){ 

        var element = new Ext.Panel({ 
         html: 'New Element' 
        }); 

        ajaxNav.add(element); 
        ajaxNav.doLayout(); 

       } 
      }] 
     }, 
     items: [{ 
      id:'tab-1', 
      html: '', 
      cls: 'card card1' 
     },{ 
      id:'tab-2', 
      html: '<p>Clicking on either side of the indicators below</p>', 
      cls: 'card card2' 
     },{ 
      id:'tab-3', 
      html: 'Card #3', 
      cls: 'card card3' 
     }] 
    }); 

} 

});

正如您所看到的,在「添加」按鈕事件中,您首先必須根據您的需要定義面板,然後將其添加到您的旋轉木馬,並且,最重要的是,您必須讓旋轉木馬重新計算他​​的佈局,調用「doLayout()」函數。

希望這會有所幫助。

+0

非常感謝,它的作品!但你知道如何刪除所有元素? – 2011-05-31 15:31:35

+0

歡迎José。當然,打開另一個問題,我會立即回覆。我更喜歡另一個問題,因爲這對於正在尋找相同事物的其他用戶甚至是有用的。 – 2011-05-31 15:37:26

+0

http://stackoverflow.com/questions/6190094/clear-all-elements-of-a-carousel-sencha – 2011-05-31 15:48:22