ExtJS如何在TreePanel中加载图片

3
我创建了一个Ext.TreePanel,我希望在节点中添加一张图片。在节点的文本中,我有图片的URL,但我无法在页面中加载它,只能看到文本。请问是否有可能查看图片?
以下是我的代码:
var root1 = new Tree.AsyncTreeNode({
    text: 'Legenda degli starti PAT',
    draggable:true, // disable root node dragging
    id:'source'
});

var tree1 = new Tree.TreePanel({
    renderTo : 'legend',
    animate:true, 
    loader: new Tree.TreeLoader({dataUrl:'legend.php'}),
    containerScroll: true,
    root: root1,
});

这是TreePanel请求的响应。
[{"text":"comuni","id":"co","leaf":false,"cls":"folder","children":[{"text":"http:\/\/localhost\
/cgi-bin\/mapserv?map=\/home\/gis\/mapserver\/cartocomune_wms.map&SERVICE=wms&FORMAT=png&VERSION=1.1
.1&LAYER=comuni&REQUEST=GetLegendGraphic","id":"comuni","leaf":true,"cls":"file"}]},{"text":"idrografia"
,"id":"id","leaf":false,"cls":"folder","children":[{"text":"http:\/\/localhost\/cgi-bin\/mapserv
?map=\/home\/gis\/mapserver\/cartocomune_wms.map&SERVICE=wms&FORMAT=png&VERSION=1.1.1&LAYER=idrografia
&REQUEST=GetLegendGraphic","id":"idrografia","leaf":true,"cls":"file"}]},{"text":"viabilita","id":"via"
,"leaf":false,"cls":"folder","children":[{"text":"http:\/\/localhost\/cgi-bin\/mapserv?map=\/home
\/gis\/mapserver\/cartocomune_wms.map&SERVICE=wms&FORMAT=png&VERSION=1.1.1&LAYER=viabilita&REQUEST=GetLegendGraphic"
,"id":"viabilita","leaf":true,"cls":"file"}]},{"text":"uso_suolo","id":"uso","leaf":false,"cls":"folder"
,"children":[{"text":"http:\/\/localhost\/cgi-bin\/mapserv?map=\/home\/gis\/mapserver\/cartocomune_wms
.map&SERVICE=wms&FORMAT=png&VERSION=1.1.1&LAYER=uso_suolo&REQUEST=GetLegendGraphic","id":"uso_suolo"
,"leaf":true,"cls":"file"}]},{"text":"catasto","id":"cat","leaf":false,"cls":"folder","children":[{"text"
:"http:\/\/localhost\/cgi-bin\/mapserv?map=\/home\/gis\/mapserver\/cartocomune_wms.map&SERVICE=wms
&FORMAT=png&VERSION=1.1.1&LAYER=catasto&REQUEST=GetLegendGraphic","id":"catasto","leaf":true,"cls":"file"
}]}]

谢谢,Luca

3个回答

1

您需要在JSON中的节点中包含一个"iconCls"属性,该属性引用定义要显示在该特定节点上的图像的CSS类。

根据extjs.com上的API文档:

// 在类的配置中指定属性: ... iconCls: 'my-icon'

// CSS类,指定要用作图标图像的背景图像: .my-icon { background-image: url(../images/my-icon.gif) 0 6px no-repeat !important; }

因此,您的JSON将如下所示:

[{"text":"comuni","id":"co","leaf":false,"cls":"folder","children":[{"text":"http://localhost\ /cgi-bin/mapserv?map=/home/gis/mapserver/cartocomune_wms.map&SERVICE=wms&FORMAT=png&VERSION=1.1 .1&LAYER=comuni&REQUEST=GetLegendGraphic","id":"comuni","leaf":true,"cls":"file", "iconCls": "my-icon"}]},{"text":"idrografia" ,"id":"id","leaf":false,"cls":"folder", "iconCls": "my-icon"} ... 等等...}]


0

请确保您的Ext.BLANK_IMAGE_URL正确指向s.gif文件


0

嗯,不清楚你的问题是什么——你是否看到了图像占位符?如果是这样,你可能需要再次检查Ext.BLANK_IMAGE_URL是否设置正确。如果你正在尝试加载自定义图像,请使用Firebug检查渲染的树节点——你的图像标签是否以正确的URL正确呈现?还要检查Firebug中的Net选项卡,看看是否有任何损坏的图像引用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接