2012-10-10 85 views
1

顯示此XML文件:如何將字符轉換爲字符串XML在ExtJS的

<ROOT> 
    <R FN="Ganapati" LN="Jena" Com="PC" /> 
    <R FN="Chandra" LN="Reddy" Com="PC"/> 
    <R FN="Charn" LN="Raj" Com="PC"/> 
    <R FN="Sunil" LN="Kumar" Com="PC"/> 
    <R FN="Muni" LN="Kiran" Com="PC"/> 
    <R FN="Raghu" LN="Kiran" Com="PC"/> 
    <R FN="Suresh" LN="Kiran" Com="PC"/> 
    <R FN="Naresh" LN="Kiran" Com="PC"/> 
    <R FN="Ranjith" LN="Kiran" Com="PC"/> 
</ROOT> 

注意如何在代碼中說Com="PC"。我想要顯示「Point Cloud」,那麼我應該如何將它映射到ExtJS中?

這是我的ExtJS的代碼:

 {name: 'FN',mapping:'@FN'}, 
     { name: 'LN',mapping:'@LN'}, 
     { name: 'Com',mapping:'@Com'}    
    ]) 
}); 

var grid = new Ext.grid.GridPanel({ 
    store: store, 
    columns: [ 
     {header: "FN", width: 120, dataIndex: 'FN'}, 
     {header: "LN", width: 100, dataIndex: 'LN'}, 
     {header: "Com", width: 115, dataIndex: 'Com'} 
    ], 

    // ... 
}); 
+0

嘗試'renderer'列http://docs.sencha.com/ext-js /4-0/#!/api/Ext.grid.column.Column-cfg-renderer – MMT

回答

1

嘗試使用渲染這樣的:

function renderCom(val, metadata, record) { 
    if (val == "PC") { 
     return "Point Cloud"; 
    } else if (val == "SE") { 
     return "Something Else"; 
    } else { 
     return val; // if nothing matches return the original value 
    } 
} 

var grid = new Ext.grid.GridPanel({ 
store: store, 
columns: [ 
    {header: "FN", width: 120, dataIndex: 'FN'}, 
    {header: "LN", width: 100, dataIndex: 'LN'}, 
    {header: "Com", width: 115, dataIndex: 'Com', renderer: renderCom} 

],