【问题标题】:Sencha Touch 2: Insert into TreeStore/NestedListSencha Touch 2:插入 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 文档中找不到一个很好的例子。

【问题讨论】:

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


【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多