stack_html += "<div class='co-stack-layer-title'>Application and Data" +
"<div class='row'>" +
response['Application and Data'].forEach(generateStackItem) +
"</div>" +
"</div>";
stack_html += "<div class='co-stack-layer-title'>Business Tools" +
"<div class='row'>" +
response['Business Tools'].forEach(generateStackItem) +
"</div>" +
"</div>";
stack_html += "<div class='co-stack-layer-title'>DevOps" +
"<div class='row'>" +
response['DevOps'].forEach(generateStackItem) +
"</div>" +
"</div>";
stack_html += "<div class='co-stack-layer-title'>Utilities" +
"<div class='row'>" +
response['Utilities'].forEach(generateStackItem) +
"</div>" +
"</div>";
function generateStackItem(element, index, array) {
var stack_item_html = "";
stack_item_html += "<div class='co-service'>" +
"<a href='" + element['canonical_url'] + "' class='each-service hint hint--top' data-hint='" + element['name'] + "' data-align='left'>" +
"<img src='" + element['image_url'] + "'>" +
"</a>" +
"</div>";
console.log(stack_item_html);
return stack_item_html;
}
我試圖用一個forEach
迭代JavaScript對象上,似乎我不能插值的返回值到字符串相加。的Javascript的forEach返回值插值到字符串
<div class='co-stack-layer-title'>Application and Data<div class='row'>undefined</div></div><div class='co-stack-layer-title'>Business Tools<div class='row'>undefined</div></div><div class='co-stack-layer-title'>DevOps<div class='row'>undefined</div></div><div class='co-stack-layer-title'>Utilities<div class='row'>undefined</div></div>
您使用的回覆如何?你想用generateStackItem做什麼? – Danmoreng