Extjs TreeStore数据被忽略

时间:2015-02-09 11:22:19

标签: extjs extjs4

我想我的一切都是正确的:

一个简单的模型:

Ext.define('js.model.MyModel', {
    extend: 'Ext.data.Model',

    fields: [
        {
            name: "name",
            type: "string"
        },
        {
            name: "type",
            type: "string"
        }
    ]
});

带树存储的树状面板:

Ext.define('js.packageDialog.ReleaseTreeView.PackageTree', {
    extend: 'Ext.tree.Panel',

    rootVisible: true,
    singleExpand: false,


    initComponent: function () {

        //Ext.create('js.model.MyModel');
        Ext.apply(this, {

            store: new Ext.data.TreeStore({
                model: 'js.model.MyModel',

                "root": {
                    "expanded": true,
                    "name": "",
                    "type": ""
                },
                proxy: {
                    type: 'memory'
                    //data: data
                }
            }),
            columns: [
                {
                    xtype: 'treecolumn',
                    text: 'Name',
                    dataIndex: 'name'
                },
                {
                    text: 'Parents',
                    dataIndex: 'parents'
                }
            ]
        });
        this.callParent();
    },


    loadData : function() {
        this.store.setRootNode(data);
    }
});

部分数据:

var data = Ext.JSON.encode({
    "children": [{
        "type": "folder",
        "name": "Photos",
        "children": [{
            "type": "JPEG",
            "name": "wedding picture"
        }, {
            "type": "JPEG",
            "name": "holiday picture"
        }
        ]
    }]
});

我把所有这些放在一起。看小提琴:

http://jsfiddle.net/x527x57t/

树面板中没有显示任何内容。列是正确的,但我的loadData()方法不起作用。

1 个答案:

答案 0 :(得分:1)

我有这样的工作:

var data = {
    children: [{
        text: "Photos",
        leaf:false,
        children: [{
            "type": "JPEG",
            text: "wedding picture",
            leaf:true
        }, {
            text: "holiday picture",
            leaf:true
        }]
    }]
};
Ext.define('js.model.MyModel', {
    extend: 'Ext.data.Model',

    fields: [
        {
            name: "text",
            type: "string"
        },
        {
            name: "type",
            type: "string"
        },
        {
            name:"leaf"
        }
    ]
});

Ext.define('js.packageDialog.ReleaseTreeView.PackageTree', {
    extend: 'Ext.tree.Panel',

    rootVisible: true,
    singleExpand: false,


    initComponent: function () {

        Ext.apply(this, {

            store: new Ext.data.TreeStore({
                model: 'js.model.MyModel',

                root: {
                    expanded: true
                    //type: ""
                },
                proxy: {
                    type: 'memory'
                    //data: data
                }
            })

        });
        this.callParent();
    },


    loadData : function() {
        this.store.setRootNode(data);
    }
});

因此,指定数据中的叶节点,TreeStore的根等属性也用引号括起来,所以我只修改了。数据现在正在显示。这可能不是正确的'回答,但我能为你提供迄今为止的一个。希望它有所帮助。