Sencha Touch 2:插入TreeStore/NestedList

Mah*_*ror 6 tree-structure nested-lists sencha-touch-2

我正在使用带有底层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();
Run Code Online (Sandbox Code Playgroud)

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

Uncaught TypeError: Cannot call method 'getSelectedName' of undefined
Run Code Online (Sandbox Code Playgroud)

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

han*_*t87 3

叶项的默认显示字段是“文本”。您可以从这里获取信息。 如果你想使用“text”作为显示字段,那么你需要将此行更改为

customerAreaNode.appendChild({text: "text", leaf:true});
Run Code Online (Sandbox Code Playgroud)

或者您可以更改嵌套列表的显示字段,因此您的模型这次不需要更改。

yournestedlist.setDisplayField('name');
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助。