我正在一个使用Kendo网格的角11项目中工作。我被要求通过自定义管道为其中一列输送数据:
@Pipe({
name: 'customPipe'
})
export class CustomPipe implements PipeTransform {
transform(id: string): string {
if (id === 'not found') {
return '---';
}
return id;
}
}管道的工作原理是我能够实现以下代码并查看--当id“未找到”时,以及在所有其他情况下id的实际值:
{{ 'found' | customPipe }}<br> <!-- prints out 'found' -->
{{ 'not found' | customPipe }} <!-- prints out '---' -->问题是,对于Kendo网格,数据从数据源中的字段绑定到网格,这些字段不是组件类的成员。因此,如果'dataSource‘是数据源,而我想要传递的字段是'file',那么网格的模板代码如下所示:
<kendo-grid [data]="dataSource" ... >
...
<kendo-grid-column field="file | customPipe" ... >
...
</kendo-grid-column>
...
</kendo-grid>我在浏览器控制台中收到一条警告:
网格列字段名“文件\customPipe”看起来不像有效的JavaScript标识符。
...and这是对的。它不是有效的Javascript标识符。‘'file’不是组件的类成员,而是数据源中的一个字段,因此在customPipe中传递它的语法是不正确的。
如何通过自定义管道在Kendo网格的数据源中输送字段?
发布于 2021-07-05 15:02:41
你应该这样写
<kendo-grid-column [field]="file | customPipe" ... >
...
</kendo-grid-column>https://stackoverflow.com/questions/68257871
复制相似问题