I am trying to extract the json content in my javascript by running it but I am not getting the desired output
My JSON is of the form
var json = [{
"html": "abc.jpg", //testing this failed
"col": 1,
"row": 1,
"size_y": 2,
"size_x": 2
}, {
"html": "def.jpg",
"col": 4,
"row": 1,
"size_y": 2,
"size_x": 2
},
{
"html": "bac.jpg",
"col": 6,
"row": 1,
"size_y": 2,
"size_x": 2
},
{
"html": "xyz.jpg",
"col": 1,
"row": 3,
"size_y": 1,
"size_x": 1
}, {
"html": "Brand.jpg",
"col": 4,
"row": 3,
"size_y": 1,
"size_x": 1
},
{
"html": "Brand.jpg",
"col": 6,
"row": 3,
"size_y": 1,
"size_x": 1
}
];
The loop which I am trying to extract content from JSON is
for(var index=0;index<json.length;index++) {
gridster.add_widget('<li class="new" ><button class="delete-widget-button" style="float: right;">-</button><img src="{% static "images/'+json[index].html+'"%}"></li>',json[index].size_x,json[index].size_y,json[index].col,json[index].row);
};
What I want is
<img src="{% static "images/abc.jpg"%}"> #for first elemet
I am sure I am missing some comma in it but not sure where exactly
Update 1
The "{% static 'images/abc.jpg' %}"
This is exact comma structure I want in my ouput
Update 2
Here's a snippet console logging the arguments I'm creating:
var json = [{
"html": "abc.jpg", //testing this failed
"col": 1,
"row": 1,
"size_y": 2,
"size_x": 2
}, {
"html": "def.jpg",
"col": 4,
"row": 1,
"size_y": 2,
"size_x": 2
}, {
"html": "bac.jpg",
"col": 6,
"row": 1,
"size_y": 2,
"size_x": 2
}, {
"html": "xyz.jpg",
"col": 1,
"row": 3,
"size_y": 1,
"size_x": 1
}, {
"html": "Brand.jpg",
"col": 4,
"row": 3,
"size_y": 1,
"size_x": 1
}, {
"html": "Brand.jpg",
"col": 6,
"row": 3,
"size_y": 1,
"size_x": 1
}
];
for (var index = 0; index < json.length; index++) {
console.log('<li class="new" ><button class="delete-widget-button" style="float: right;">-</button><img src="{% static "images/' + json[index].html + '"%}"></li>', json[index].size_x, json[index].size_y, json[index].col, json[index].row);
};