Last active
November 19, 2018 13:17
-
-
Save chj1768/8e4376b8a6b3fcbd6711a6c9f51efb58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Renderer = class { | |
async render(data){ | |
if(!(data instanceof Data)) throw "invalid data type"; | |
const info = await data.getData(); | |
if(!(info instanceof Info)) throw "invalid info type"; | |
this._title = info.title; | |
this._header = info.header; | |
this._items = info.items; | |
this._render(); | |
} | |
_render(){ | |
throw "_render must overrided"; | |
} | |
}; | |
const TableRenderer = class extends Renderer{ | |
constructor(parent){ | |
if(typeof parent != 'string' || !parent) throw "invalid param"; | |
super(); | |
this._parent = parent; | |
} | |
_render(){ | |
const parent = document.querySelector(this._parent); | |
if(!parent) throw "invaild parent"; | |
parent.innerHTML= ""; | |
const [table, caption, thead] = "table,caption,thead".split(",").map(v=>document.createElement(v)); | |
caption.innerHTML= this._title; | |
[caption, this._header.reduce((_, v)=>(thead.appendChild(document.createElement("th")).innerHTML = v, thead)), | |
...this._items.map(item=>item.reduce((tr, v)=>(tr.appendChild(document.createElement("td")).innerHTML = v, tr), | |
document.createElement("tr")))].forEach(el=>table.appendChild(el)); | |
parent.appendChild(table); | |
} | |
} | |
경우님! 과제의 의도에 맞게 바꿔주셨으나, json을 넣었을 때 출력 값이 제대로 나오지 않습니다. 그래서 어쩔 수 없이 0점드렸어요 ㅠㅠ 다시 작성해서 올려주시면 점수 올려드리겠습니다~!
오타수정했습니다 👍
@chj1768 점수 올려드렸습니다 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
경우님! 과제의 의도에 맞게 바꿔주셨으나, json을 넣었을 때 출력 값이 제대로 나오지 않습니다. 그래서 어쩔 수 없이 0점드렸어요 ㅠㅠ 다시 작성해서 올려주시면 점수 올려드리겠습니다~!