我正在使用带有XMLReader的ExtJS在GridPanel中显示内容。这可以很好地工作,但是我的XML源代码具有不可预测的重复元素数量:
<beamline>
<technique>Tomography</technique>
<technique>Phase contrast imaging</technique>
<technique>Microdiffraction</technique>
<technique>General diffraction</technique>
</beamline>可能有0-30个<technique>元素。
目前,我正在使用:nth(n)选项在XMLReader中手动提取这些内容:
{name: 'technique1', mapping: 'technique:nth(1)'},
{name: 'technique2', mapping: 'technique:nth(2)'},然后将这些作为列放置在面板中,并与渲染器函数连接:
{header: "Technique", width: 100, dataIndex: 'technique1', sortable: false, renderer: techniques},
{header: "Technique2", dataIndex: 'discipline2', hidden: true},
function techniques(val, x, store){
return '<ul><li>'+val+'</li><li>'+store.data.technique2+'</li></ul>';
}但这显然太笨拙了,无法扩展。有没有通用的(循环或XPath风格的)方法来实现类似的结果?
发布于 2010-11-11 18:52:36
我没有使用过XML阅读器,但是我遇到了一个类似的问题,我必须显示一行,其中一列可以包含N个项目。

假设techniques列包含一个对象数组,您可以将其呈现为
function techniquesRenderer(val){
var returnValue = '<ul>';
for(var v in val){
var foo = val[v];
returnValue += '<li>' + foo.someProperty + '</li>';
}
return returnValue += '</ul>
}希望这能有所帮助。
https://stackoverflow.com/questions/4078984
复制相似问题