0

ツリーストアからデータを取得するツリービューがあります。ただし、ツリー構造の一部として表示される小さなフォルダーのみを表示できます。ノードの名前が表示されません。レコードを印刷しようとすると、空の文字列と表示されます。コードは次のとおりです。

アプリ/表示

Ext.define('App.view.Hierarchy', {
    alias: 'widget.hierarchy',
    extend: 'Ext.panel.Panel',

    initComponent: function () {

        var config = {

            xtype: 'panel',
            border: false,
            autoScroll: true,
            baseCls: 'topMenu',
            html: '<div class="PageTitle" style="width:600px;"><b>' + LANG.HIERARCHYT + '</b><br>' + LANG.HIERARCHYTxt + '<br>' + '</div>',


            items: [{
                xtype: 'toolbar',
                border: false,
                dock: 'top',
                items: [{
                    xtype: 'button',
                    text: LANG.BTADDREG,
                    iconCls: 'icon-add-tb',
                    cls: 'tip-btn',
                    iconAlign: 'right',
                    action: 'addRegion',
                    id: 'ADDREGION'
                }]

            },

            {
                xtype: 'treepanel',
                title: 'Hierarchy Tree',
                id: 'hierarchyTree',
                border: false,
                alias: 'widget.hierarchyTree',
                height: 1000,
                viewConfig: {
                    enableDD: true,
                    plugins: {
                        ptype: 'treeviewdragdrop'
                    }
                },
                collapsible: false,
                useArrows: true,
                rootVisible: false,
                store: Ext.create('Campus.store.HierarchyTree'),
                displayField: 'Title',
                multiSelect: false,
                singleExpand: false,


            }]
        }

        var holder = Ext.getCmp('center');
        holder.remove(0);
        holder.add(Ext.apply(config));
        this.callParent(arguments);
    }
});

モデル

Ext.define('App.model.HierarchyTree', {
    extend : 'Ext.data.Model',
    fields : ['Title', 'ID', 'LevelID', 'ParentID'] 
});

Ext.define('App.store.HierarchyTree', {
    extend: 'Ext.data.TreeStore',
    model: 'App.model.HierarchyTree',
    storeID: 'HierarchyTree',

    proxy: {
        type: 'ajax',
        url: 'data/Locations.aspx',

        reader: {

        },
        actionMethods: {
            create: 'POST',
            read: 'POST',
            update: 'POST'
        },
        extraParams: {
            mode: 'HIERARCHYFULLLIST'


        }
    },
    autoLoad: true
});

コントローラ

Ext.define('App.controller.Hierarchy', {
    extend: 'Ext.app.Controller',
    stores: ['Me', 'Regions', 'Areas', 'Towns', 'HierarchyTree'],
    model: ['Me', 'Teams', 'Regions', 'User', 'HierarchyTree'],
    views: ['App.view.Hierarchy', 'App.view.AddRegions'],
    refs: [{
        ref: 'myHierarchyTree',
        selector: 'hierarchyTree'
    }],

    init: function () {

        this.getHierarchyTreeStore().load();

        this.control({
            'button[action=addRegion]': {
                click: this.addRegion
            },
            '#hierarchyTree': {
                itemclick: this.itemclick

            }
        })
    },
    itemclick: function (view, record) {
        console.log(record.get('Title'))
    }
});

また、返されるJSONは次のとおりです。

{"text":".","children": [{"text":"Asia Pacific","id":"537","level":"1", "expanded": 
 false,"singleClickExpand":true,"children":[{"text":"Japan", "cls":"xtreenode-Level2-
Indent", "id":"538", "hl1":"537","level":"2","singleClickExpand":true, "expanded":   
false, "children":[]},
4

2 に答える 2

1

Treepanelの表示フィールドはデフォルトでテキストに設定されます。これはjsonが返されるので問題ありませんが、問題はストアモデルであり、フィールドとしてテキスト、cls、およびjsonにあるその他の属性を含める必要があります。そうしないと、これらはレコードにマップされず、空のテキストが表示されます。

Ext.define('App.model.HierarchyTree', {
extend : 'Ext.data.Model',
fields : ['Title', 'ID', 'LevelID', 'ParentID', 'text', 'level','cls,....]

編集

displayFieldをTitleに変更しましたが、jsonにtitle属性が含まれていません。テキストが実際にタイトルである場合はモデルを変更するか、簡単に修正する必要があります。これを行うには、フィールドへのマッピングを設定します。

  Ext.define('App.model.HierarchyTree', {
    extend : 'Ext.data.Model',
    fields : [{name:'Title',type:'string',mapping:'text'}, 'ID', 'LevelID', 'ParentID',]

これにより、タイトルにjsonからのテキスト値が入力されます。

また、displayField構成を削除すると、テキスト値が適用されますが、これは「タイトル」値が空になることを意味します。

于 2012-09-06T14:28:15.367 に答える
1

OK、ついにわかりました:)ツリーの表示フィールドを「テキスト」に設定します

 displayfield : 'text'

そして、もう一度nscrobに感謝します

そしてもう1つ質問があります。クリックされているツリーのレベルに応じて、さまざまなビューを開く方法についてのガイダンスを教えてください。

これは機能します。

if (record.get('level')==1) 
    {
        this.erWin = Ext.create('App.view.EditRegions');

        this.erWin.showWin();
    }
    else{
        //open another_view
    }
于 2012-09-06T14:50:40.160 に答える