我正在使用带有基础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();


此代码在叶级别(在正确的节点之后)导致两个新的空listentry,在节点级别导致一个新的侦听。
每个新条目在NestedList中都没有显示名称,但是每个项目的名称字段中都包含“文本”。奇怪的是,叶级别的新条目之一未键入基础模型。因此找不到对应于模型的方法:

Uncaught TypeError: Cannot call method 'getSelectedName' of undefined


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

最佳答案

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

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


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

yournestedlist.setDisplayField('name');


希望这可以帮助。

07-24 13:47