Sencha Touch 2:插入TreeStore / NestedList

时间:2012-03-19 09:40:55

标签: sencha-touch-2 nested-lists tree-structure

我正在使用带有底层TreeStore的NestedList。现在我想将项目添加到NestedList中作为叶子。 我怎么能这样做?

目前我的代码(Controller,onAddButtonTapped)如下所示:

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

此代码在叶级别(正确节点后面)和节点级别上的一个新侦听中产生两个新的空侦听。 每个新条目都没有在NestedList中显示的名称,但每个项目的名称字段中都包含“text”。奇怪的是,叶级别的一个新条目没有输入到底层模型。因此无法找到与模型相对应的方法:

Uncaught TypeError: Cannot call method 'getSelectedName' of undefined

有没有人知道如何将数据添加到NestedList / TreeStore的简单教程?我在sencha touch docs中找不到一个好的例子。

2 个答案:

答案 0 :(得分:3)

叶项的默认显示字段是“text”。 You can get the information from here.如果您想使用“text”作为显示字段,则需要将此行更改为

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

或者您可以更改嵌套列表的显示字段,因此您的模型此时无需更改。

yournestedlist.setDisplayField('name');

希望这有帮助。

答案 1 :(得分:0)

在我的情况下,我曾经像以下方式更新根节点和子节点

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