Sencha Touch 2: Insert into TreeStore / NestedList

I am using a NestedList with a base TreeStore. Now I want to add elements to the NestedList as leaves. How can i do this?

Currently my code (Controller, onAddButtonTapped) is as follows:

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 items at the sheet level (behind the correct node) and one new listener at the node level. Each new entry does not have names displayed in the NestedList, but each element contains β€œtext” in the name field. Curiously, one of the new entries at the sheet level is not introduced into the base model. Thus, one could find methods suitable for the model:

 Uncaught TypeError: Cannot call method 'getSelectedName' of undefined 

Does anyone know a simple tutorial on how to add data to a NestedList / TreeStore? I could not find one good example in sencha touch docs.

+6
source share
2 answers

The default display field for sheet elements is "text." You can get the information here. If you want to use β€œtext” as the display field, you need to change this line to

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

Or you can change the display field of the nested list so that your model does not change during this time.

 yournestedlist.setDisplayField('name'); 

Hope this helps.

+3
source

In my case, I used to update the root and child nodes as follows

 Ext.getStore('Contactsstore').getAt(1).getChildAt(0).set('Email',contactemail); Ext.getStore('Contactsstore').getAt(1).set('ContactTitle',contacttitle); 
0
source

Source: https://habr.com/ru/post/911078/


All Articles