const obj =
{
"Lillian" : { "type": "The Guardian", "portfolioImage": "./img/TheGuardian/Lillian.png" },
"Annalise" : { "type": "TheGuardian", "portfolioImage": "./img/TheGuardian/Annalise.png" },
"Raven" : { "type": "DCComics", "portfolioImage": "./img/TheGuardian/Raven.png" }
};
let images = [];
for(let item in obj){
images.push(item.portfolioImage);
}
: 여기
{
"Lillian" : {
"type": "The Guardian",
"portfolioImage": "./img/TheGuardian/Lillian.png"
},
"Annalise" : {
"type": "TheGuardian",
"portfolioImage": "./img/TheGuardian/Annalise.png"
},
"Raven" : {
"type": "DCComics",
"portfolioImage": "./img/TheGuardian/Raven.png"
}
}
내 HTML입니다 : 여기
내 JSON의 HTML에서 요소의
src
속성을 sourc로 설정하려고합니다. 이미지에 e. 다음 예제는 JSON을 루프 처리하고 모든 이미지를 한 번에 표시하는 방법을 보여줍니다.
const JSON = {
Lillian: {
type: 'The Guardian',
portfolioImage: './img/TheGuardian/Lillian.png'
},
Annalise: {
type: 'TheGuardian',
portfolioImage: './img/TheGuardian/Annalise.png'
},
Raven: { type: 'DCComics', portfolioImage: './img/TheGuardian/Raven.png' }
};
class Example extends React.Component {
render() {
return (
<div>
{Object.keys(JSON).map(key => (
<div>
{JSON[key].type}
<img src={JSON[key].portfolioImage} key={key} />
</div>
))}
</div>
);
}
}
ReactDOM.render(<Example />, document.getElementById('root'));
태그를 생성하고 경로를 src 속성에 배치하면 어떨까요? – Borjante