Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sencha Touch 2: Insert into TreeStore/NestedList

I'm using a NestedList with a underlying TreeStore. Now I want to add items to the NestedList as leafs. How can I do this?

Currently my code (Controller, onAddButtonTapped) looks like this:

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

This code results in two new empty listentries on leaf level (behind the correct node) and one new listentry on node level. Every new entry has no names shown in the NestedList but every item contains "text" in their name field. Curiously one of the new entries at leaf level is not typed to the underlying Model. So the model-corresponding methods could't be found:

Uncaught TypeError: Cannot call method 'getSelectedName' of undefined

Does anybody know a easy tutorial how to add data into NestedList/TreeStore? I could not find one good example in the sencha touch docs.

like image 808
Mahatma_Fatal_Error Avatar asked Mar 19 '12 09:03

Mahatma_Fatal_Error


1 Answers

The default display field for leaf items is "text". You can get the information from here. If you want to use "text" as display field, then you need to change this line to

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

Or you can change your nested list's display field, so your model do not need to change for this time.

yournestedlist.setDisplayField('name');

Hope this helps.

like image 84
handet87 Avatar answered Dec 18 '22 08:12

handet87