Skip to content

Instantly share code, notes, and snippets.

@chj1768
Last active November 19, 2018 13:17
Show Gist options
  • Save chj1768/8e4376b8a6b3fcbd6711a6c9f51efb58 to your computer and use it in GitHub Desktop.
Save chj1768/8e4376b8a6b3fcbd6711a6c9f51efb58 to your computer and use it in GitHub Desktop.
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);
}
}
@Duckuism
Copy link

경우님! 과제의 의도에 맞게 바꿔주셨으나, json을 넣었을 때 출력 값이 제대로 나오지 않습니다. 그래서 어쩔 수 없이 0점드렸어요 ㅠㅠ 다시 작성해서 올려주시면 점수 올려드리겠습니다~!

@chj1768
Copy link
Author

chj1768 commented Nov 17, 2018

경우님! 과제의 의도에 맞게 바꿔주셨으나, json을 넣었을 때 출력 값이 제대로 나오지 않습니다. 그래서 어쩔 수 없이 0점드렸어요 ㅠㅠ 다시 작성해서 올려주시면 점수 올려드리겠습니다~!

오타수정했습니다 👍

@Duckuism
Copy link

@chj1768 점수 올려드렸습니다 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment