function categoryDetails(catId, code, label) {
alert('Inside Categories Detail')
$.post("/product/categories", {
catId: catId,
code: code,
label: label,
sess: socket.id
}).done(function(data) {
alert("Inside product capacity" + data.result)
console.log(data.result)
//In the below line I am trying to access the data parameter of the function but it says undefined
var botHtml = '<div class="nn-bot-bubble"><div class="nn-bot-chips">{% for i in data.result %}<button id="sel_btn" value="{{ i.label }}"> {{ i.label }} </button>{% endfor %}</div></div>'
$(".chat_block").append(botHtml);
});
Here the data parameter is a dictionary with the key named 'result' and value a 'list'.
Thanks in advance!!!
function categoryDetails(catId,code,label){
alert('Inside Categories Detail')
$.post("/product/categories", {catId: catId,code:code,label:label, sess: socket.id}).done(function(data) {
var text='';
var middle='';
var result='';
capacitylist=data.result
var start= '<div class="nn-bot-bubble"><div class="nn-bot-chips"><div class="button_block">'
for (i = 0; i < capacitylist.length; i++){
text = capacitylist[i]['label'];
result='<button id="sel_btn" value="'+text+'">'+text+'</button>'
middle+=result
}
end='</div></div></div>'
botHtml=start+result+end
$(".chat_block").append(botHtml);
});
}
So here instead of running a loop inside the DOM, I used a javascript loop and then combined it.