【发布时间】:2016-12-18 07:34:12
【问题描述】:
我遇到了 Aurelia 的问题,并假设我缺少某些东西。
我正在尝试创建一个“通用”网格。我删除了很多 html 以保持示例简短,但基本思想是这样的:
<template>
<require from="../value-converters"></require>
<table show.bind="rows.length">
<thead>
<tr>
<th repeat.for="columnDefinition of columnDefinitions">
${columnDefinition.displayName}
</th>
</tr>
</thead>
<tbody>
<tr repeat.for="row of rows">
<td repeat.for="columnDefinition of columnDefinitions">
<span if.bind="columnDefinition.isCurrency">${row[columnDefinition.propertyName] | numeralFormatter}</span>
<span if.bind="columnDefinition.isDate">${row[columnDefinition.propertyName] | dateFormatter}</span>
<span if.bind="!columnDefinition.isCurrency && !columnDefinition.isDate &&">${row[columnDefinition.propertyName]}</span>
</td>
</tr>
</tbody>
</table>
</template>
我希望能够使用 ValueConverters 来帮助正确显示某些类型的列数据。以上目前正在工作,但我希望为其他列提供更多价值转换器,并且条件会变得笨拙。到目前为止,我对 Aurelia 的体验是它提供了相当优雅的解决方案,但我至今无法弄清楚这一点。
我尝试向 columnDefinition 类添加另一个属性,例如 formatter:string = undefined,然后尝试创建如下跨度:
<span if.bind="columnDefinition.formatter">${row[columnDefinition.propertyName] | columnDefinition.formatter}</span>
<span if.bind="!columnDefinition.formatter">${row[columnDefinition.propertyName]}</span>
但是解析器在 '.' 上抛出了一个错误。
有什么方法可以实现吗?处理此类问题的“aurelia 方式”是什么。
提前感谢您提供的任何帮助。
【问题讨论】:
标签: aurelia