【发布时间】:2018-06-30 07:12:13
【问题描述】:
是否可以在模板文字中返回 ForEach 中的字符串值,以便将其添加到该位置?因为如果我记录它,它会返回undefined。还是像我输入的那样根本不可能?
return `<div>
<form id='changeExchangeForViewing'>
<label for='choiceExchangeForLoading'>Change the exchange</label>
<div class='form-inline'>
<select id='choiceExchangeForLoading' name='choiceExchangeForLoading' class='form-control'>
${Object.keys(obj).forEach(function (key) {
return "<option value='" + key + "'>" + obj[key] + "</option>"
})}
`;
【问题讨论】:
-
与我下面的评论相关:jsfiddle.net/Lwt6aLyp/1
标签: javascript jquery string template-literals