如何替换图像? [英] How to replace the image?

查看:74
本文介绍了如何替换图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码显示树结构.当我单击图像Pic.gif时,它必须替换为新图像.同样,pic1.gif到新图像,pic6.gif到新图像.完全适合此代码的代码????

Below code displays the tree structure.When i click on the image Pic.gif,it has to get replaced by new image.Similarly pic1.gif to new image,pic6.gif to new image.Can you help mw with the code where exactly it fits in this code ????

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
        })
    });
});

推荐答案

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

You need to trigger the icon change when the node is expanded using the beforeexpand listener:

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

您也可以在其他节点上重复该操作.

You can repeat that for your other node also.

这篇关于如何替换图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆