Answer the question
In order to leave comments, you need to log in
What is the best way to create blocks from data?
There is this HTML:
<template id="ctmp">
<div>
.........Куча дочерних и вложенных в них элементов.......
</div>
</template>
<div id="dump">
<!--Блок для вывода-->
</div>
var cloneNode = $(ctmp.content.children[0]);
//Получил json
var newBox = document.createDocumentFragment();
json.forEach(function(article){
var newArticle = cloneNode.clone();
cloneNode.find(".contentBox").text(article.text);
cloneNode.find(".contentTitle").text(article.name);
//И примерно 10 подобных манипуляций
newBox.appendChild(cloneNode);
}
dump.appendChild(newBox);
Answer the question
In order to leave comments, you need to log in
Use a templating engine, the best way to turn JSON data into HTML, as optimized as possible.
- Handlebars.js
- Dust.js
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question