2010-11-02 53 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