【发布时间】:2019-06-18 20:58:49
【问题描述】:
我通过使用不带花括号的箭头函数将数据从我的对象完美呈现到 DOM。
我尝试在相同的箭头函数之后添加花括号。 DOM 不会渲染任何数据。
CODE WORKS WITHOUT CURLY BRACES AFTER ARROW FUNCTION
function displayMatches () {
const matchArray = findMatches(this.value, cities)
console.log(matchArray)
const html = matchArray.map(place =>
`<li>
<span class="name">${place.city}, ${place.state}</span>
<span class="population">${place.population}</span>
</li>`
).join('')
suggestion.innerHTML = html
}
THE SAME CODE BREAKS WITH CURLY BRACES AFTER ARROW FUNCTION
function displayMatches () {
const matchArray = findMatches(this.value, cities)
console.log(matchArray)
const html = matchArray.map(place => {
return
`<li>
<span class="name">${place.city}, ${place.state}</span>
<span class="population">${place.population}</span>
</li>`
}).join('')
suggestion.innerHTML = html
}
【问题讨论】:
标签: javascript