【发布时间】:2020-12-22 20:56:59
【问题描述】:
重复for循环中使用的数组
let loopArr = ["item.name + ' /'+ item.DisplayName? item.DisplayName: item.otherDisplayName",
"item.description + ' /'+ item.anotherDescription"]
模板
<div repeat.for = item of data">
<div repeat.for = "row of loopArr">
<span textcontent.bind="renderRow(row, item)></span>
</div>
</div>
组件方法
renderRow(row, item){
return eval(row)
}
其实我想在模板中显示如下
<div repeat.for = item of data">
<div repeat.for = "row of loopArr">
<span>${item.name + ' /'+ item.DisplayName? item.DisplayName: item.otherDisplayName} </span>
<span>${item.description + ' /'+ item.anotherDescription} </span>
</div>
</div>
由于我想循环遍历dynamic loopArr,而不是使用eval从字符串转换为值,有没有更好的方法来计算字符串的值?此外,eval 不适用于多行语句,是否有任何其他方法/方式来处理上述问题?
如何将字符串转换为值并在aurelia模板中显示?
任何帮助将不胜感激!
【问题讨论】:
-
你的问题不清楚(至少对我来说)。你能给我们一个你正在使用的示例数据集以及你想要在渲染后实现的 html 结果吗? gist.dumber.app 起点也不错,我们可以从该起点着手解决问题
-
感谢您的回复,我现在得到了解决方案,下次我将添加一个工作示例
标签: javascript aurelia aurelia-templating