0

我遇到了一个问题,在定义带有内联存储的 TreePanel 时,我看不到树节点的文本。但是,如果我将存储定义外部化并将其移动到一个单独的变量中,然后如 API 文档中所示为其分配 TreePanel,它就可以正常工作。

以下是 TreePanel 的代码片段以及它在渲染时的样子:

    Ext.define('MyApp.view.MyViewport', {
    extend: 'Ext.container.Viewport',
    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [ {
                    xtype: 'treepanel',
                    title: 'My Tree Panel',
                    displayField: 'text',
                    store: {
                      "id" : "xwt-gen-92bb1629-2cfe-43c1-a40a-a8a2c4e26562",
                      "owners" : ["booktaxi.tree"],
                      "storeId" : "xwt-gen-6310be92-f272-4926-8392-ed0eacd04952",
                      "fields" : [],
                      "root" : {
                        "children" : [{
                            "children" : [],
                            "expandable" : false,
                            "id" : "775aa413-72af-4708-b2f1-8852a660cd0a",
                            "leaf" : true,
                            "root" : false,
                            "text" : "detention"
                          }, {
                            "children" : [{
                                "children" : [],
                                "expandable" : false,
                                "id" : "f2cbb9c3-c177-4870-a2f2-dceb54a781ab",
                                "leaf" : true,
                                "root" : false,
                                "text" : "book report"
                              }, {
                                "children" : [],
                                "expandable" : false,
                                "id" : "a4550d10-385e-4c2e-b6da-9f439cab8bd4",
                                "leaf" : true,
                                "root" : false,
                                "text" : "alegrbra"
                              }
                            ],
                            "expandable" : true,
                            "id" : "ba8910a3-7e3f-4959-bcd0-9b3c102c40d4",
                            "leaf" : false,
                            "root" : false,
                            "text" : "homework"
                          }, {
                            "children" : [],
                            "expandable" : false,
                            "id" : "4f855b01-24ab-400a-ad7d-0dff14ca9710",
                            "leaf" : true,
                            "root" : false,
                            "text" : "buy lottery tickets"
                          }
                        ],
                        "expanded" : true,
                        "id" : "a7d67f78-1a32-4077-8ce3-778b40de1835",
                        "leaf" : false,
                        "root" : true,
                        "text" : ""
                      },
                      "xtype" : "store.tree"
                    },
                    viewConfig: {

                    }
                }
            ]
        });

        me.callParent(arguments);
    }
});

内联定义存储时的TreePanel

我想知道是否有人以前遇到过这个问题,是否有办法解决这个问题。

4

2 回答 2

2

您应该fields在商店定义中指定 ,因为您没有明确指定模型。

于 2013-06-25T07:45:36.337 回答
0

displayField重命名dispalyField

Ext.applyIf(me, {
            items: [ {
                    xtype: 'treepanel',
                    title: 'My Tree Panel',
                    dispalyField: 'text', <---- ** displayField **

编辑:

在树视图上:

this.columns = [{
    header      : "Name header 1",
    xtype       : 'treecolumn',
    iconCls      : '',
    dataIndex   : 'index1',
    flex        : 1
},{
    header      : "Name header 2",
    dataIndex   : 'index2'
},{
    header      : "Name header 3",
    dataIndex   : 'index3'
},{
    header      : "Name header 4",
    dataIndex   : 'index4'
},{
    header      : "Name header 5",
    dataIndex   : 'index5'
}];

dataIndex需要与定义的数据同名。

"children" : [{
    index1  : 'file', // Father name
    index2  : 'data1'
    ...
    children : [{
                    index1           : 'children file',
                    index2  : 'children data1',
                    ...
                    leaf : true
                }]
}]
于 2013-06-25T07:32:19.953 回答