【问题标题】:selecting node when using treeStore ExtJS (proxy solution)使用treeStore ExtJS时选择节点(代理解决方案)
【发布时间】:2013-10-16 09:13:17
【问题描述】:

我有树店。

var store = Ext.create('Ext.data.TreeStore', {
    root: {
        autoLoad:false,
        expanded: false,
        children: [
            { 
                id:"0", text: "School Friends", expanded: true, children: 
                [
                    {
                        id:"1", text: "Mike", leaf: true, name: "Mike", email: "mike@stackoverflow.com", phone: "345-2222"
                    },
                    {
                        id:"select", text: "Laura", leaf: true, name: "Laura", email: "laura@stackoverflow.com", phone: "345-3333"
                    }
                ] 
            }

        ]
    }
});

和树面板。

Ext.create('Ext.tree.Panel', {
    title: 'Simple Tree',
    width: 200,
    height: 150,
    store: store,
    rootVisible: false,
    renderTo: Ext.getBody(),
    listeners:{
        afterrender:function(){
          var record = this.getStore().getNodeById('1');
          this.getSelectionModel().select(record)
        }
    }
});

一切正常!但是当我更改商店时,使用代理请求。选择没有*不起作用*

    var storeTree = Ext.create('Ext.data.TreeStore', {
    autoLoad:true,
    expanded: true,

    proxy: {
        type: 'ajax',
        url: 'tree.json',
    },

    root: {
        text: 'Ext JS',
        id: 'src',
        expanded: true,
      // children:[]
    },

    folderSort: true,
    sorters: [{
        property: 'text',
        direction: 'ASC'
    }]
});

我使用相同的 JSON

[

    {"id":4, "text":"second",},

    {
    id:"0", text: "School Friends", expanded: true, children: 
                [
                    {
                        id:"1", text: "Mike", leaf: true, name: "Mike", email: "mike@stackoverflow.com", phone: "345-2222"
                    },
                    {
                        id:"select", text: "Laura", leaf: true, name: "Laura", email: "laura@stackoverflow.com", phone: "345-3333"
                    }
                ] 

    },

]

【问题讨论】:

    标签: extjs extjs4 extjs4.1 extjs4.2


    【解决方案1】:

    例如一种解决方案:

     var storeTree = Ext.create('Ext.data.TreeStore', {
        autoLoad:false,
        expanded: false,
    
        proxy: {
            type: 'ajax',
            url: 'tree2.json',
    
            extraParams: {o: 'SELECTED'},
        },
    
        root: {
            text: 'Ext JS',
            id: 'src',
            expanded: true,
            children:[]
        },
    
        folderSort: true,
        sorters: [{
            property: 'text',
            direction: 'ASC'
        }]
    });
    
    
    storeTree.load({
        url: 'tree.json'
    });
    
    
     storeTree.on({
        'load': function(store) {
            var node = store.getNodeById("select"); // your id here
    
            treePanel.getSelectionModel().select([node]);
            treePanel.selectPath(node.getPath());
        },
        single: true
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-18
      • 2016-09-03
      • 1970-01-01
      • 1970-01-01
      • 2013-07-20
      相关资源
      最近更新 更多