2012-03-19 96 views
6

我正在使用帶有基礎TreeStore的NestedList。現在我想將項目添加到NestedList作爲葉子。 我該怎麼做?Sencha Touch 2:插入到TreeStore /嵌套列表

目前我的代碼(控制器,onAddButtonTapped)看起來是這樣的:

var store = Ext.getStore('menuStore'); 
var customerAreaNode = store.getRoot().getChildAt(1); 
customerAreaNode.appendChild({name: "text", leaf:true}); 
customerAreaNode.expand(); 
store.sync(); 

此代碼導致在葉級兩個新的空listentries(正確的節點後面),並在節點級一個新的一個ListEntry。 每個新條目都沒有名稱顯示在嵌套列表中,但每個條目都在其名稱字段中包含「文本」。奇怪的是,葉級的新條目中沒有一個輸入到底層模型中。因此,相應的模型的方法便無法找到:

Uncaught TypeError: Cannot call method 'getSelectedName' of undefined 

有誰知道一個簡單的教程如何將數據添加到NestedList/TreeStore?我無法在sencha touch文檔中找到一個很好的例子。

+0

這可能幫助:http://stackoverflow.com/questions/9655201/update-a-nested-list-in -sencha-touch-2 ---即時通訊在我的手機上,所以我無法測試代碼,看看是否讓你開始 – 2012-08-15 14:03:48

回答

3

葉子項目的默認顯示字段是「文本」。 You can get the information from here.如果你想用「文字」作爲顯示領域,那麼你就需要這條線變爲

customerAreaNode.appendChild({text: "text", leaf:true}); 

或者你可以改變你的嵌套列表的顯示領域,使你的模型並不需要更改這個時間。

yournestedlist.setDisplayField('name'); 

希望這會有所幫助。

0

在我來說,我用來更新根和子節點,如下面的方式

Ext.getStore('Contactsstore').getAt(1).getChildAt(0).set('Email',contactemail);  
Ext.getStore('Contactsstore').getAt(1).set('ContactTitle',contacttitle); 
相關問題