如何更换图像?

时间:2011-03-04 07:15:09

标签: extjs

下面的代码显示树形结构。当我点击图像Pic.gif时,它必须被新图像替换。类似于pic1.gif到新图像,pic6.gif到新图像。可以帮助mw与代码恰好适合这段代码????

var children = [{
    text: 'family',
    icon: 'pic1.gif',
    children: [{
        text: 'parent1',
        icon: 'pic2.gif',
        children: [{
            icon: 'pic3.gif',
            text: 'children1',
            leaf: true},
        {
            icon: 'pic4.gif',
            text: 'children2',
            leaf: true},
        {
            icon: 'pic5.gif',
            text: 'children3',
            leaf: true}]}],

    },
{
    text: 'Parent2',
    icon: 'pic6.gif',
    children: [{
        icon: 'pic7.gif',
        text: 'children4',
        leaf: true},
    {
        icon: 'pic8.gif',
        text: 'children5',
        leaf: true},
    {
        icon: 'pic9.gif',
        text: "children6",
        leaf: true}]}];
Ext.onReady(function() {
    var tree = new Ext.tree.TreePanel({
        loader: new Ext.tree.TreeLoader(),
        width: 1000,
        height: 1000,
        renderTo: Ext.getBody(),
        root: new Ext.tree.AsyncTreeNode({
            expanded: false,
            leaf: false,
            icon: 'pic.gif'

            ,
            text: 'Head',
            children: children
        })
    });
});

1 个答案:

答案 0 :(得分:3)

使用beforeexpand侦听器扩展节点时,需要触发图标更改:

var children = [{
    text: 'family',
    icon: 'pic1.gif',
    listeners: {
       'beforeexpand': function(node) {
           node.setIcon('newImage.gif');
       }
    }
    children: [{
    //...

您也可以为其他节点重复此操作。