1

子要素を持つJsonデータがあります。ストアを編集可能なグリッドにバインドし、編集内容をストアに入力する必要があります。データツリーはItemFileWriteStoreに入力されます。datagridには、親データのみが表示され、子データは表示されません。

SAMPLE.TXT

    {
    "items": [
        {
            "profileId": "1",
            "profileName": "ABC",
            "profileType": "EmailProfile",
            "profilePreferences": [
                {
                    "profilePreferenceId": "1",
                    "displayText": "Bob",
                    "address": "primary@some.com"
                },
                {
                    "profilePreferenceId": "2",
                    "displayText": "Sally",
                    "address": "secondary@some.com"
                },
                {
                    "profilePreferenceId": "3",
                    "displayText": "Joe",
                    "address": "alternate@some.com"
                }
            ]
        }
    ]
}

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();
}
4

1 に答える 1

1

すべての偶数行に空白のprofileNameを表示するには、 dojox.grid.TreeGridまたは「偽の」JSONを使用する必要があります。2つのサンプルが続きます。1つはTreeGrid用で、もう1つはDataGrid上にあります。ただし、作業環境ではテストされていません。

与えられた階層型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'
     } ]

DataGrid構造

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

参照道場ドキュメント

于 2012-05-01T06:15:24.960 に答える