考慮下面的代碼片段我想:如何在字符串中使用運算符三元組?
<script>
for (var key in photoList) {
if(key == photoList[key].id) {
var res = `<li id="thumbnail-`+key+`">
<div class="thumbnail `+(product.photo == photoList[key].id)+` ? 'thumbnail-main' : ''">
...
</div>
</li>`;
}
}
</script>
我嘗試這樣,但它沒有工作?我該怎麼做?
的可能的複製[?如何寫用jQuery這個三元操作符(https://stackoverflow.com/questions/6595585/how-to-write-這三元操作符與jquery) –
https://stackoverflow.com/questions/6259982/how-do-you-use-the-conditional-operator-in-javascript – user7929528
Theres a'before the?使它成爲一個字符串 –