2016-10-20 17 views
0

私はテーブルを作ることができるようにこのJSONを反復しようとしていますが、多くのヘッダとデータがあるので、どうやってこれをやりなおすことができますか?このJSONを反復でマップして反復する方法

const BBDDCustomer = { 
     ui_labels: { 
     name: 'Name', 
     address: 'address', 
     postalCode: 'Postal Code', 
     city: 'City', 
     country: 'Country', 
     telephone: 'Telephone', 
     email: 'Email', 
     modified: 'Modified', 
     delete: 'Delete' 

     }, 
    data: [ 
    { 
     name: 'n1', 
     address: 'a1', 
     postalCode: 'PC 1', 
     city: 'c 1', 
     country: 'cou 1', 
     telephone: 'tel 1', 
     email: 'em 1' 
    } 
} 

私はこのように記述する必要はありません。

<table striped bordered condensed hover responsive> 
     <thead> 
     <tr> 
     <th>{BBDDCustomer.ui_labels.name}</th> 
     <th>{BBDDCustomer.ui_labels.address}</th> 
     <th>{BBDDCustomer.ui_labels.postalCode}</th> 
     <th>{BBDDCustomer.ui_labels.city}</th> 
     <th>{BBDDCustomer.ui_labels.country}</th> 
     <th>{BBDDCustomer.ui_labels.telephone}</th> 
     <th>{BBDDCustomer.ui_labels.email}</th> 
     <th>{BBDDCustomer.ui_labels.modified}</th> 
     <th>{BBDDCustomer.ui_labels.delete}</th> 
     </tr> 
</table> 
+2

を使いたいためにプロパティを列挙する必要がありますそれはない* JSON *> [何?](http://stackoverflow.com/questions/2904131/what-of-the-difference-json-and-object-literal-notation) –

+0

'Map.php'を' map'と組み合わせて使うことができます。しかし、プロパティの順序は保証されていません。 –

+0

答えはそれではないですか?構造体をマップしてレンダリングします。あなたはそれを行うために反応を学ぶ必要があります –

答えて

0

あなたは

const columns = ['name', 'address', ...]; 

map

<Table striped bordered condensed hover responsive> 
     <thead> 
     <tr> 
      { 
      columns.map(column => (
       <th key={column}>{BBDDCustomer.ui_labels[column]}</th> 
      )) 
      } 
     </tr> 
     </thead> 
     <tbody> 
     { 
      BBDDCustomer.data.map((data, i) =>(
      <tr key={i}> 
       { 
       columns.map(column => (
        <td key={column + i}>{data[column]}</td> 
       )) 
       } 
      </tr> 
     )) 
     } 
     </tbody> 
</Table> 
+0

ユリーはスポットです。彼のアプローチのバリエーションは次のとおりです。http://codepen.io/PiotrBerebecki/pen/jrQZvA –