Sencha Touch 2:插入 TreeStore/NestedList

Posted

技术标签:

【中文标题】Sencha Touch 2:插入 TreeStore/NestedList【英文标题】:Sencha Touch 2: Insert into TreeStore/NestedList 【发布时间】:2012-03-19 09:40:55 【问题描述】:

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

目前我的代码(控制器,onAddButtonTapped)如下所示:

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

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

Uncaught TypeError: Cannot call method 'getSelectedName' of undefined

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

【问题讨论】:

这可能会有所帮助:***.com/questions/9655201/… --- 我在我的手机上,所以我无法测试代码,看看这是否能让你开始 【参考方案1】:

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

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

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

yournestedlist.setDisplayField('name');

希望这会有所帮助。

【讨论】:

【参考方案2】:

在我的例子中,我曾经像下面这样更新根节点和子节点

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

【讨论】:

以上是关于Sencha Touch 2:插入 TreeStore/NestedList的主要内容,如果未能解决你的问题,请参考以下文章

将 Sencha Architect 项目从 Sencha Touch v2.0.x 更新到 Sencha Touch 2.1.x

将 Sencha Touch 1.X 升级到 Sencha Touch 2.X

在 mac 上安装 sencha-touch 2.1

Sencha Touch 2 或 DHTMLX Touch

touch-chart 1.0 是不是与 sencha touch 2.0 兼容?

Sencha Touch 2 在轮播下方添加导航栏