728x90
function findBoard() {
const id = /*[[ ${id} ]]*/;
fetch(`/api/events/${id}`).then(response => {
console.log('response',response); // json 데이터 파싱
if (!response.ok) {
throw new Error('Request failed...');
}
return response.json();
}).then(json => {
console.table(json); // json 데이터 가져옴.
json.createdDate = moment(json.createdDate).format('YYYY-MM-DD HH:mm:ss');
console.log(Object.keys(json),'Object.keys(json)'); // json 데이터를 key로 만듬.
console.log('document.getElementById(title)',document.getElementById('title'));
Object.keys(json).forEach(key => { // 해당 키를 document.getelementById 각각의 id html 태그에 넣어라 라는뜻
const elem = document.getElementById(key);
console.log('elem',elem);
if (elem) {
elem.innerText = json[key];
console.log('json[key',json[key]);
}
});
}).catch(error => {
alert('게시글 정보를 찾을 수 없습니다.');
goList();
});
}
'개념 정리' 카테고리의 다른 글
javascript에서 파라미터만 잘라서 사용 할 때 사용 (0) | 2022.08.05 |
---|---|
css에서 요소에 스타일 줄 때 (0) | 2022.08.04 |
만들어진 변수 return (0) | 2022.08.02 |
Spring RequestBody & ResponseBody (0) | 2022.07.29 |
FilenameUtils, RandomStringUtils -> gradle (0) | 2022.07.22 |