How to replace the image?

放肆的年华 提交于 2019-12-25 08:27:26

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/5190821/how-to-replace-the-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!