2013-07-23 34 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的回答发表评论,所以我只是做一个新的答案)