【发布时间】:2019-12-11 11:02:52
【问题描述】:
我正在使用来自 Syncfusion Angular UI Components (Essential JS 2) 的 Grid 组件 (ejs-grid)。
一个问题是,当使用列模板时,我无法从数据源访问当前行的原始对象。这就是为什么点击Stackblitz中某个单元格中的黑色方块后,网格下的输出是:
是否一样:假
let-data 变量不保存数据源中的原始对象,而是保存它的一些副本。
HTML 模板:
<ejs-grid [dataSource]='data' rowHeight='38' height='200' width="300">
<e-columns>
<e-column field='name' headerText='Employee Name' width='200'>
<ng-template #template let-data>
<div>
<span>{{ data.name }}</span>
<span>{{ data.testFunc() }}</span>
<span
(click)="onClick(data)"
class="clickable">
</span>
</div>
</ng-template>
</e-column>
</e-columns>
</ejs-grid>
<div>Is the same: {{ isTheSame !== undefined ? isTheSame : 'undefined' }}</div>
TypeScript 组件代码:
export class Item {
public constructor(public readonly name: string) {
}
public testFunc(): string {
return "testFunc " + this.name;
}
}
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
providers: [FilterService,VirtualScrollService]
})
export class AppComponent {
public data: ReadonlyArray<any> = [new Item("Name1")];
public isTheSame: boolean | undefined;
public onClick(dataItem: any): void {
this.isTheSame = dataItem === this.data[0];
}
}
除了
let-data,还有其他变量可以绑定列模板来获取原始行数据吗?如果没有,有什么解决方法?谁能指出我的 docs\Gitub 源代码,其中包含列模板可用的所有变量的列表?除了
let-data:let-clientData,我至少还知道一个。
【问题讨论】:
标签: angular typescript syncfusion