2012-04-30 23 views
1

私は子要素を持つJsonデータを持っています。私はストアを編集可能なグリッドにバインドし、編集内容をストアに移入させる必要があります。 データツリーがItemFileWriteStoreに読み込まれます。データグリッドは親データのみを表示し、子データは表示しません。階層型JsonをItemFileWriteStoreにマップする方法は?

SAMPLE.TXT

{ 
    "items": [ 
     { 
      "profileId": "1", 
      "profileName": "ABC", 
      "profileType": "EmailProfile", 
      "profilePreferences": [ 
       { 
        "profilePreferenceId": "1", 
        "displayText": "Bob", 
        "address": "[email protected]" 
       }, 
       { 
        "profilePreferenceId": "2", 
        "displayText": "Sally", 
        "address": "[email protected]" 
       }, 
       { 
        "profilePreferenceId": "3", 
        "displayText": "Joe", 
        "address": "[email protected]" 
       } 
      ] 
     } 
    ] 
} 

あなたはすべてのも空白のプロファイル名を持つ行提示するdojox.grid.TreeGridか '偽' JSONを使用する必要がjavascriptの

var sampleLayout = [ 
    [ 
    { field: 'profileName', name: 'profileName', width: '100px' }, 
    { field: 'profilePreferences.displayText', name: 'displayText', width: '100px' }, 
    { field: 'profilePreferences.address', name: 'address', width: '100px' }  
    ]]; 


function populateGrid() { 
    var url = "sample.txt"; //Will be replaced with endpoint URL 

    dojo.xhrGet({ 
     handleAs: 'json', 
     url: url, 
     error: function (e) { 
      alert("Error: " + e.message); 
     }, 
     load: showJsonData 
    }); 
} 


function showJsonData(response, ioArgs) { 
    var profileStore = new dojo.data.ItemFileWriteStore({ 
     data: { 
      items: response.items 
     } 
    }); 

    var sampleGrid = dijit.byId("sampleGrid"); 
    sampleGrid.store = profileStore; 
    sampleGrid.startup(); 
} 
+0

表示はどのように見えますか? (ネストされた行は別のクラス名でフラット化されます) – fncomp

+0

ディスプレイは、3つの列(profileName、displayText、address)を持つグリッドにフラット化する必要があります。グリッドには3つの行があります。 profilePreferencesごとに1つ。 –

答えて

1

。 2つのサンプルが続きます.1つはDataGridの別のTreeGrid用で、作業環境ではテストされていません。

Hierachial JSON考える:

{ 
    identifier: 'id' // a good custom to make an id pr item, note spaces and odd chars are invalid 

     items: [{ 
     id: '1', 
     profileName: 'Admin', 
     profilePreferences: [ 
      { id: '1_1', displayText: 'John Doe', address: 'Big Apple' } 
      { id: '1_2', displayText: 'Jane Doe', address: 'Hollywood' } 
     ] 

     }, { 
     id: '2', 
     profileName: 'Visitor', 
     profilePreferences: [ 
      { id: '2_1', displayText: 'Foo', address: 'Texas' } 
      { id: '2_2', displayText: 'Bar', address: 'Indiana' } 
     ] 

     }] 
    } 

TreeGrid構造

{ 
    cells: [ 
     [ 
     { field: "profileName", name: "profileName", width: "100px" }, 
     { field: "profilePreferences", 
      children: [ 
      { field: "displayText" name: "displayText", width: "100px" }, 
      { field: "address" name: "address", width: "100px" } 
      ] 
     ] 
    ] 
    } 

参照:dojo docs

は「偽-子供JSONを平らに考える:

{ 
    identifier: 'id' // a good custom to make an id pr item, note spaces and odd chars are invalid 

     items: [{ 
     id: '1', 
     profileName: 'Admin', preferenceText: '', preferenceAddr: '' 
    }, { 
     id: '2', 
     profileName: '',  preferenceText: 'John', preferenceAddr: 'NY' 
    }, { 
     id: '3', 
     profileName: 'Visitor', preferenceText: '', preferenceAddr: '' 
    }, { 

     id: '4',   // Not with '.' dot seperator like so 
     profileName: '', preference.Text: 'Jane Doe', preference.Addr: 'Hollywood' 
    } ] 

データグリッド構造

[[ 
    {'name': 'Profilename', 'field': 'profileName', 'width': '100px'}, 
    {'name': 'User name', 'field': 'preferenceText', 'width': '100px'}, 
    {'name': 'Address', 'field': 'preferenceAddr', 'width': '200px'} 
]] 

参照dojo docs

+0

私はフラットなビューとしてプレゼンテーションされます。また、私が受け取るJSON構造には柔軟性が限られています。 –

+0

TreeGridとの互換性を保つために、子要素の名前を常に「子孫」にする必要があるのは不思議ですね。もしそうなら、それは複数の異なる名前の子ノードをどのように扱うでしょうか?モデルに依存する –

+0

jsonを制御しない場合は、ForestStoreModel config(ctor)パラメータ 'childrenAttrs'を調べてください。しかし、標準グリッドはモデルレスであり、付属の店舗で直接動作しますので、 – mschr

関連する問題