diff --git a/list-editor/index.js b/list-editor/index.js index 11be6c5..e993863 100644 --- a/list-editor/index.js +++ b/list-editor/index.js @@ -176,6 +176,38 @@ function editor(root, inputData, options) { return el; } + // TODO: build an actual tree of list items + function renderTree(rootElement, rootData) { + const el = (tag, children = []) => { + let elt = document.createElement(tag) + _.each(children, item => { + elt.appendChild(item) + }) + return elt + } + + /** + * @param {Item[]} items + * @returns {*} + */ + let buildTree = (items) => { + return _.map(items, (item) => { + return el("li", [ + el("div", [document.createTextNode(item.text)]), + el("ul", buildTree(item.children)) + ]) + }) + } + + let tree = rootData.tree(); + $(rootElement).children().remove() + + let $list = buildTree(tree) + let $ul = $('