2012-02-16 84 views
0

因此,讓我們在煎茶觸摸說,我創建了一個嵌套列表,像這樣Sencha Touch - 如何在嵌套列表中顯示最新的內容?

var NestedList = createList(jsonDataObject,'leftNavigation','list','bookmark-icon'); 
function createList(data , id , cls, iconCls) 
{ 
    var store = new Ext.data.TreeStore({ 
     model: 'ListItem', 
     root: data, 
     proxy: { 
      type: 'ajax', 
      reader: { 
      type: 'tree', 
      root: 'items' 
      } 
     } 
    }); 

    var leftNav = new Ext.NestedList({ 
     // cardSwitchAnimation: false, 
     dock: 'left', 
     id: id, 
     cls: 'card '+cls, 
     useTitleAsBackText: true, 
     title: data.text , 
     iconCls: iconCls, 
     displayField: 'text', 
     width: '350', 
     store: store}); 
} 

一段時間後,jsonDataObject內容將發生變化(無論是定期通過電話setInterval()或因用戶交互)。我可能還需要向NestedList商店提交全新的jsonDataObject。所以我的問題是:

a)如何讓NestedList刷新並顯示新的用戶界面?

b)我的實施createList()是最適合創建Nestlisted的方法嗎?還是有更好的方式來達到我的目的?

回答

0

因爲沒有人及時回答我的問題,所以我用了一個工作。

我在問題中保留了代碼。嵌套列表由容器面板使用。所以我做的是從容器面板中刪除舊的嵌套列表,將其銷燬,然後創建一個新的嵌套列表,並將其插回容器面板。舉個例子:

// my old nestedlist was item 1 of the container, where container is Ext.TabPanel() 
// you can re-use this strategy with any component in the container.items.items array 
var oldnestedlist = container.items.items[1]; 
container.remove(oldnestedlist); 
oldnestedlist.destroy(); 

// create the new nestedlist 
var NestedList = createList(jsonDataObject,'leftNavigation','list','bookmark-icon'); 
container.insert(1,NestedList); 
// After you insert the NestedList, the screen hasn't been redrawn yet, 
// so i force the user to go back to screen if container.items.items[0] via 
// setActiveItem(0). You can choose the screen in any other 
// container.items.items array 
container.setActiveItem(0); 

// Next time someone presses the tab for containers.items.items[1], the screen will automatically redraw 
相關問題