I am trying to generate an HTML from a JSON object. Please have a look at my required output HTML and JSON below
Required generated HTML
<div class="container">
<div class="row">
<div class="col col-sm-5">Span 5</div>
<div class="col col-sm-3">Span 3</div>
<div class="col col-sm-2">
<div class="col col-sm-12">Span 2</div>
<div class="col col-sm-12">Span 2</div>
</div>
</div>
</div>
JSON
[
{
"Name": "span5",
"RowSpan":2,
"ColSpan": 5
},
{
"Name": "span3",
"RowSpan": 2,
"ColSpan": 3
},
{
"Name": "span2",
"RowSpan": 1,
"ColSpan": 2
},
{
"Name": "span2",
"RowSpan": 1,
"ColSpan": 2
}
]
The code which I tried is below, which is not working as expected, I am able to implement colspan but, I am not sure how do I implement rowspan.
The last span2 cell should come below third span2 cell and that way first and second cells should occupie two rows as their rowspan is 2
https://jsfiddle.net/v1mzn6bu/
HTML
<div class="container">
<div id="replica" class="row">
</div>
</div>
Javascript
var replica = document.getElementById('replica');
for(var i = 0; i < json.length; i++) {
replica.innerHTML += '<div class="col col-sm-' + json[i].ColSpan + '">' + json[i].Name + '</div>';
}


Childrenproperty and add a conditional nested for loop for them to keep the structure same as the required output.