将静态数据加载到Ext.data.TreeStore [英] Load static data to Ext.data.TreeStore

查看:138
本文介绍了将静态数据加载到Ext.data.TreeStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将一些静态数据加载到 Ext.data.TreeStore 实例吗?
Ext.data.Store非常简单 - 所有我们要做的 - 是添加数据参数进行配置。

Can I load some static data to Ext.data.TreeStore instance? It is pretty straightforward for Ext.data.Store - all we have to do - is to add data param to config.

但是我看不到这样的东西为 Ext.data.TreeStore

But I can not see such thing for Ext.data.TreeStore.

推荐答案

创建具有内存代理的TreeStore实例,然后将商店的ROOT NODE设置为您拥有的静态数据。

Create the TreeStore instance with a memory proxy, and then set the ROOT NODE of the store to the static data that you've got.

Ext.define('Task', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'task', type: 'string'},
        {name: 'user', type: 'string'}
    ]
});

var store = Ext.create('Ext.data.TreeStore', {
    model: 'Task',
    proxy: {
        type: 'memory'
    },
    folderSort: true
});

var data = {
    "text":".",
    "children": 
        [
            {
                task:'Project: Shopping', 
                user:'Will', 
                iconCls:'task-folder', 
                expanded: true,
                children:
                [
                    {
                        task:'Housewares', 
                        user:'Will', 
                        iconCls:'task-folder',
                        expanded: true,
                        children:[
                            { 
                                task:'Kitchen supplies', 
                                user:'Alpha', 
                                leaf:true, 
                                iconCls:'task' 
                            },
                            { 
                                task:'Groceries', 
                                user:'Bravo', 
                                leaf:true, 
                                iconCls:'task' 
                            }
                        ]
                    }
                ]
            }
        ]
    };

var rootNode = store.setRootNode(data);

这篇关于将静态数据加载到Ext.data.TreeStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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