Created
April 28, 2021 15:23
-
-
Save m-yahya/cdef4b78315e423886bce1ee736e267c to your computer and use it in GitHub Desktop.
Tutorial: Nested UI from JSON data and Tree view
This file contains hidden or 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
// get details | |
const getDetails = (details) => { | |
// iterate over the detail items of object | |
for (const detail in details) { | |
// fetch the value of each item | |
if (detail == "img") { | |
markupArray.push( | |
`<img src="./img/${details[detail]}" alt="${details[detail]}">` | |
); | |
} else if (detail == "children") { | |
markupArray.push("<ul>"); | |
details[detail].forEach((element) => { | |
getItems(element); | |
}); | |
markupArray.push("</ul>"); | |
} else { | |
markupArray.push(`<span> ${details[detail]} </span>`); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment