2012-11-02 27 views
1

我有這個問題,jqGrid中的treegrid在通過xml傳遞數據時忽略了最後一個選項(擴展節點或不)。任何人遇到這個?有解決方案嗎?也許是我的數據?這裏是產生問題的樣本數據:jqGrid treegrid在提供xml數據時忽略擴展狀態

<rows> 
    <page>1</page> 
    <total>0</total> 
    <records>4</records> 
    <row id='2'> 
      <cell>2</cell> 
      <cell>Parent</cell> 
      <cell>0</cell> 
      <cell>NULL</cell> 
      <cell>false</cell> 
      <cell>true</cell> 
      </row> 
    <row id='1'> 
      <cell>1</cell> 
      <cell>Child 1</cell> 
      <cell>1</cell> 
      <cell>2</cell> 
      <cell>true</cell> 
      <cell>false</cell> 
      </row> 
    <row id='3'> 
      <cell>3</cell> 
      <cell>Child 2</cell> 
      <cell>1</cell> 
      <cell>2</cell> 
      <cell>true</cell> 
      <cell>false</cell> 
      </row> 
    <row id='4'> 
      <cell>4</cell> 
      <cell>Child 3</cell> 
      <cell>1</cell> 
      <cell>2</cell> 
      <cell>true</cell> 
      <cell>false</cell> 
      </row> 
</rows> 

回答

1

這似乎對我來說更在的TreeGrid的錯誤。不過,您可以通過loaded: true屬性添加到需要擴展的節點來輕鬆解決問題。在的代碼the line的原因和上面的一些線(見here)其中loaded屬性(和ldat[loaded])將undefined等等ldat[expanded]將改爲undefined用於不具有定義loaded所有項目。

The demo演示解決方案。它使用您張貼,但與另外<cell>true</cell>"Parent"項目定義的末尾添加XML:

... 
<row id='2'> 
    <cell>2</cell> 
    <cell>Parent</cell> 
    <cell>0</cell> 
    <cell>NULL</cell> 
    <cell>false</cell> 
    <cell>true</cell> 
    <cell>true</cell> <!-- added the element for loaded: true --> 
</row> 
... 

修訂:我認爲,最簡單的方法來解決(最初描述here)的錯誤將是改變的代碼setTreeNode

ldat[expanded] = ((ldat[expanded] == "true" || ldat[expanded] === true) ? true : false) && 
    ldat[loaded]; 

the line以下

ldat[expanded] = ((ldat[expanded] == "true" || ldat[expanded] === true) ? true : false) && 
    (ldat[loaded] || ldat[loaded] === undefined); 

請參閱the corresponding demo使用固定代碼。

+0

謝謝!我發現這個帶有load參數的舊bug,但是創建者說在幾個月前已經解決了。我沒有弄清楚如何在新版本中應用這個解決方法,只是爲了嘗試,因爲源代碼已經改變了,但它確實有效。謝謝! –

+0

@MihalisBagos:不客氣!我會試着分析一下'setTreeNode'的代碼,併發布我的建議如何修復bug。如果我會這樣做,我會通知你。 – Oleg

+0

@MihalisBagos:我更新了我的回答,並提供了修正錯誤的建議。 – Oleg