【发布时间】:2018-03-13 22:52:59
【问题描述】:
我有一个 ng2-smart-table,我希望它的第二列是一个复选框,该复选框默认选中或为空,具体取决于作为我的源的数据对象的第四列二进制值。所以现在我有
export class UsermanagementComponent implements OnInit {
settings:Object;
data:Object;
public input: string = '<input type="checkbox"></input>';
constructor(private _sanitizer: DomSanitizer) {
this.settings = {
columns: {
username: {
title: 'User Name'
},
checkbox: {
title: 'Inactive',
type: 'html',
valuePrepareFunction: (value) => { return this._sanitizer.bypassSecurityTrustHtml(this.input); },
filter: false
}
}
};
this.data = [
{
username: "Bret",
checkbox:'yes'
},
{
username: "Antonette",
checkbox:'no'
}
];
}
我已根据需要导入了 Ng2SmartTableModule 和 DomSanitizer。这是填充复选框,与 this.data 中的复选框中设置的内容无关。与 checkbox:true 或 checkbox:1 相同。这是我所预料的。因为我没有在任何地方映射 if checkbox:yes 然后将第 i 个可迭代对象的公共字符串设置为
<input type = 'checkbox' checked></input>
我该怎么做?提前致谢。
【问题讨论】:
-
你只是在寻找类似
<input [(ngModel)]="checkboxValue" type="checkbox" name="checkbox">的东西吗? -
也许可以,但是如何将其映射到 ng-2-smart-table 的源数据对象?