Tim*_*Tim 4 typescript angular
我从服务器返回一个包含列数组的对象及其定义和行数组.我想在构建HTML表格时迭代列和行,并根据使用"格式"管道返回的列类型格式化单元格.
例如
WS响应:
{
"columns" [{"precision":10,"name":"PAGES","typeName":"INTEGER","scale":0...,
"rows":[{"PAGES":6531....}, [{"PAGES":6531....}]
}
Run Code Online (Sandbox Code Playgroud)
HTML片段:
<tr *ngFor="let row of invoices?.rows">
<td *ngFor="let column of invoices?.columns>
{{row[column.name] | format : column}}
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
有没有办法我的"格式"管道可以作为一个委托人到正确的内置管道(一个退出),具体取决于列的类型?我不想重新实现DecimalPipe,DatePipe等.
是的,你可以调用管道 - 只需实例化它们并调用transform:
transform(cell: any, column: any): any {
if (column.typeName === "INTEGER") {
let pipe = new DecimalPipe();
return pipe.transform(cell, "1.0-0");
}
// more here ...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2026 次 |
| 最近记录: |