2010-11-02 52 views
0

我正在使用ExtJS和XMLReader在GridPanel中显示内容。这工作得很好,但是我的XML源具有重复元素的不可预知号码:在ExtJS网格中处理不可预知的XML数据

<beamline> 
    <technique>Tomography</technique> 
    <technique>Phase contrast imaging</technique> 
    <technique>Microdiffraction</technique> 
    <technique>General diffraction</technique> 
</beamline> 

有可能是任何地方从0-30 <technique>元素。

目前我手动XMLReader可以使用这些拉出:第n个(n)的选项:

{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风格)方法来实现类似的结果?

回答

0

我还没有使用XML阅读器,但我有一个类似的问题,我不得不显示一列,其中列可以包含N项。

Screenshot showing problem

假设的技术列包含对象的数组,你可以呈现为

function techniquesRenderer(val){ 
    var returnValue = '<ul>'; 
    for(var v in val){ 
    var foo = val[v]; 
    returnValue += '<li>' + foo.someProperty + '</li>'; 
    } 
    return returnValue += '</ul> 
} 

希望这有助于。

+0

谢谢,DanB,我会放弃它。 – Jonas 2010-12-03 04:26:38