2011-08-05 8 views
2

ExtJS4を使用してTreePanelを作成します。だから私はどのように私は"en"ノードが私のルートノードにしたい場合は、私のストアを設定する必要があります。フォーマットExtJS4 JSONからTreePanelsルートノードを設定する方法

{"text":"en","children": 
    {"text":"/","children":[ 
     {"text":"/page","children":[ 
      {"text":"/page/new","children":[],"leaf":true,"expanded":false}, 
      {"text":"/page/remove","children":[],"leaf":true,"expanded":false} 
     ],"leaf":false,"expanded":false}, 
     {"text":"/home","children":[],"leaf":true,"expanded":false} 
    ],"leaf":false,"expanded":true} 
} 

を以下ましたプロキシリーダーにJSONを送信しています私はroot: 'My Root'としてTreeStoreのルートを定義するとき

Ext.define('Example.store.WebItems', { 
    extend: 'Ext.data.TreeStore', 

    model: 'Example.model.Item', 

    proxy: { 
     type: 'ajax', 
     api: { 
      read : 'some/url', 
     }, 
     reader: { 
      type: 'json', 
      root: 'children' // Is this correct? 
     } 
    }, 
    root: // What should I write here? 
}); 

それは新しいルートが追加されますが、私はJSONで定義されたルートを使用します。だから、私の質問は以下のとおりです。

  1. はどのてmanualyそれを定義するのではなく、JSONからのルートノードを使用しますか?
  2. プロキシリーダーとTreeStoreにもルートノードを定義する必要がありますか?

答えて

5

応答にはrootが必要です。たとえば、

この例では、rootは「MyRoot」です。

 // ... 
     reader: { 
      type: 'json', 
      root: 'MyRoot' 
     } 
    }, 
    //root: this config is not needed now 
}); 
+4

お返事ありがとうございます。私は 'Ext.tree.Panel'のプロパティ' rootVisible'を 'false'に設定しなければならないということを追加したいだけです。それ以外の場合、ツリーはロードされません。 – kurochenko

+0

rootVisibleをfalseに設定すると、私が探していた秘密が...ありがとう! – prototype

1

私が知っている1として、次のようにルートを指定する必要があります。

root : { 
text : 'en', 
id : 'src', 
expanded : true' 
} 

は、それはあなたを助けるスニペット上記のコードを試してみてください。

+0

お返事ありがとう!残念ながら、手動でrootを追加するだけです。私は望みません。 – kurochenko

0

が遅れるが、他人のために、JSON内の配列は[]ちょうどこのようにラップする可能性があります:
[{"text":"en","children": {"text":"/","children":[ {"text":"/page","children":[ {"text":"/page/new","children":[],"leaf":true,"expanded":false}, {"text":"/page/remove","children":[],"leaf":true,"expanded":false} ],"leaf":false,"expanded":false}, {"text":"/home","children":[],"leaf":true,"expanded":false} ],"leaf":false,"expanded":true} }]
リーダーブロックを削除する今、あなたはあなたのrootが「MyRoot」で読者に「伝える」ために持っています
reader: { type: 'json', root: 'MyRoot' }

ルートブロックを追加します。

root : { text : 'en', id : 'src', expanded : true' }

trepanelにrootVisible: falseを追加

関連する問題