2013-07-23 31 views
0

我正在使用GeoExt(基於ExtJs)創建樹。在每個節點中,我需要左側的對應圖像,而不是像this site那樣的默認圖像default image。我該怎麼做?使用Extjs更改樹節點中的默認圖像

編輯

我發現this example但我不知道我怎麼可以添加兒童

編輯2 這裏是我的代碼部分:

var bpn = new OpenLayers.Layer.WMS("bpn", 
    url, 
    { 
     LAYERS: [ 'Año 2004', 'Año 2005', 'Año 2006', 'Año 2007', 'Año 2009'], 
     format: "image/png", 
     transparent: "true", 
     projection: 'EPSG:4326' 
    }, 
    { 
     buffer: 0, 
     displayOutsideMaxExtent: true, 
     isBaseLayer: false, 
     displayInLayerSwitcher: false, 
     yx: {'EPSG:4326' : true} 
     }); 

var treeConfig = [ 
    { 
     nodeType: "gx_layer", 
     layer: bpn, 
     isLeaf: false, 

     loader: { 
      param: "LAYERS", 

     }, 
     expanded: false 
    }]; 

tree = new Ext.tree.TreePanel({ 
    border: true, 
    region: "west", 
    title: "Entre Ríos", 
    width: 250, 
    split: true, 
    collapsible: true, 
    collapseMode: "mini", 
    autoScroll: true, 

    loader: new Ext.tree.TreeLoader({ 
     applyLoader: true, 
     uiProviders: { 
      "layernodeui": LayerNodeUI 
     } 
    }), 
    root: { 
     nodeType: "async", 
     children: treeConfig 
    },  
    rootVisible: false, 
    lines: false, 
}); 

每層(節點)'Año 2004', 'Año 2005', 'Año 2006', 'Año 2007', 'Año 2009'有不同的圖像。我應該在treeConfig更改哪些內容?

回答

1

這是通過在節點數據中使用iconCls字段實現的。

編輯

的例子(見fiddle):

Ext.widget('treepanel', { 
    renderTo: Ext.getBody(), 
    height: 200, 
    store: new Ext.data.TreeStore({ 
     root: { 
      text: 'Root', 
      expanded: true, 
      children: [{ 
       text: 'Node 1', 
       iconCls: 'icon1' 
      },{ 
       text: 'Node 2', 
       iconCls: 'icon2' 
      },{ 
       text: 'Node 3', 
       iconCls: 'icon1' 
      }] 
     } 
    }) 
}); 
+0

的問題是,每個節點都有一個不同的圖標。 –

+0

是的,這是每個節點的屬性...請參閱我的示例。 – rixo

+0

謝謝。如果你想看到我的**編輯2 **。對不起,我不太瞭解這個圖書館。 –

0

rixo是正確的,你必須使用iconCls設置圖標的每個節點。就你而言,rixo示例中的「children」屬性與「treeConfig」數組相同。所以你必須在「treeConfig」數組元素中添加「iconCls」。

當前你只有一個子節點(層)元素,你可以在你的「treeConfig」數組中添加更多的子節點(層)。

(抱歉,我沒有足夠的聲譽上rixo的回答發表評論,所以我只是做一個新的答案)