2013-06-11 75 views
1

實施例的XML文件中的存儲相結合記錄:ExtJS的在具有相同的字段

<BrowserInformation> 
     <Value> 
      <Year>2011</Year> 
      <Name>Firefox</Name> 
      <Count>4952</Count> 
     </Value> 
      <Year>2011</Year> 
      <Name>MSIE</Name> 
      <Count>4613</Count> 
     <Value> 
      <Year>2011</Year> 
      <Name>Chrome</Name> 
      <Count>1401</Count> 
     </Value> 
     <Value> 
      <Year>2011</Year> 
      <Name>Safari</Name> 
      <Count>1111</Count> 
     </Value> 
     <Value> 
      <Year>2011</Year> 
      <Name>Unknown</Name> 
      <Count>1119</Count> 
     </Value> 
     <Value> 
      <Year>2011</Year> 
      <Name>Opera</Name> 
      <Count>9</Count> 
     </Value> 
     <Value> 
      <Year>2012</Year> 
      <Name>Firefox</Name> 
      <Count>3544</Count> 
     </Value> 
      ... 
</BrowserInformation> 

柱形圖製備: enter image description here

目前,有在圖表中爲XML中的每個記錄中的條文件。我想得到每個瀏覽器的總計數(即對於Firefox,它將是4952 + 3544)。數據和商店類的配置選項idProperty和石斑魚似乎只是將相同名稱的酒吧放在圖表的相鄰位置,但似乎並未將它們結合起來。假定文件中的數據不能改變。我怎麼做到這一點?是否有可以在模型,商店或圖表中設置的特定配置屬性?如果是這樣?還是有另一種方式?

+0

做下面爲你工作的解決方案? – Christoph

回答

2

我建議在模型中使用一個新字段,比如說「total」,並使用convert函數。

Ext JS API documentation

「如果需要更復雜的值提取的策略,然後用一個轉換功能配置的領域。這是通過全行對象,並可以詢問它的任何方式是必要的,以便返回所需的數據。「然後

你的轉換功能,可以是這樣的

function convert2Total(v, record){ 
    return record.data.firefox + record.data.chrome; 
} 

你的領域模型中的數組,那麼應該是這樣的:

fields: [ { name: "firefox" }, 
      { name: "chrome" }, 
      { name: "total", convert: convert2Total }] 
相關問題