2016-07-28 9 views
0

を反応させ、ネイティブが、私はこの中のような配列を持つネイティブ

const data = [ 
    { key: 1, label: 'Service1'}, 
    { key: 2, label: 'Service2' }, 
    { key: 3, label: 'Service3' }, 
    { key: 4, label: 'Service4' }, 
    { key: 5, label: 'Service4' }, 
]; 

とJSONデータの反応:

"services": [ 
    { 
     "id": 1, 
     "name": "Hotels", 
    }, 
    { 
     "id": 2, 
     "name": "Embassies", 
    }, 
] 

どのようにmap IDラベルへの鍵と名前にしますか? ??

答えて

1

const dataにJSONの値を入力してください。正しいですか?

これを試してみてください:

var jsonData = { 
 
    "services": [ 
 
    { "id": 1, "name": "Hotels" }, 
 
    { "id": 2, "name": "Embassies" } 
 
    ] 
 
}; 
 

 
var data = jsonData.services.map(function(item) { 
 
    return { 
 
    key: item.id, 
 
    label: item.name 
 
    }; 
 
}); 
 

 
console.log(data);

関連する問題