Sencha Touch 2:插入TreeStore/NestedList [英] Sencha Touch 2: Insert into TreeStore/NestedList

查看:94
本文介绍了Sencha Touch 2:插入TreeStore/NestedList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将NestedList与基础TreeStore一起使用.现在,我想将叶子添加到NestedList中. 我该怎么办?

I'm using a NestedList with a underlying TreeStore. Now I want to add items to the NestedList as leafs. How can I do this?

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

Currently my code (Controller, onAddButtonTapped) looks like this:

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

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

This code results in two new empty listentries on leaf level (behind the correct node) and one new listentry on node level. Every new entry has no names shown in the NestedList but every item contains "text" in their name field. Curiously one of the new entries at leaf level is not typed to the underlying Model. So the model-corresponding methods could't be found:

Uncaught TypeError: Cannot call method 'getSelectedName' of undefined

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

Does anybody know a easy tutorial how to add data into NestedList/TreeStore? I could not find one good example in the sencha touch docs.

推荐答案

叶项的默认显示字段为文本". 您可以从此处获取信息. 如果要使用文本"作为显示字段,则需要将此行更改为

The default display field for leaf items is "text". You can get the information from here. If you want to use "text" as display field, then you need to change this line to

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

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

Or you can change your nested list's display field, so your model do not need to change for this time.

yournestedlist.setDisplayField('name');

希望这会有所帮助.

这篇关于Sencha Touch 2:插入TreeStore/NestedList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆