渲染树后,Ext.data.TreeStore修改了数据源?

时间:2014-05-12 10:07:33

标签: extjs tree sencha-touch store

假设我的数据源如下:

var data = [
    {
        id: 1,
        name: 'name1',
        parentId: null,
        children: [
            {
                id: 2,
                name: 'name2',
                parentId: 1
            }
        ]
    },
    {
        id: 3,
        name: 'name3',
        parentId: null,
        children: [
            {
                id: 4,
                name: 'name4',
                parentId: 3
            }
        ]
    }
]

代码片段如下:

var basic_grid_store = Ext.create('Ext.data.TreeStore', {
    storeId: 'basic_grid_store',
    model: 'TestModel',
    root: {
        children: []
    }
});

console.log(data);
// the data structure is correct at this time

basic_grid_store.setRootNode({children: data);

console.log(data);
// the data structure is incorrect at this time, in which the `children` attribute for each item was gone.

我找不到任何相关的文档,有人可以说明为什么TreeStore修改了我的数据源,因为它不应该发生?

1 个答案:

答案 0 :(得分:0)

是的,它 更改了原始数组。我无法回答为什么会出现这种情况,你需要问Ext架构师/开发人员,但你能尝试的是:

basic_grid_store.setRootNode({children:Ext.clone(data)});