Sencha Touch 2: Insert into TreeStore/NestedList

谁都会走 提交于 2019-12-07 03:04:07

问题


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.


回答1:


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.




回答2:


In my case i used to update root and child nodes like the following way

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


来源:https://stackoverflow.com/questions/9767890/sencha-touch-2-insert-into-treestore-nestedlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!