1

我有一个 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>

我怎么做?提前致谢。

4

1 回答 1

0

import { DomSanitizer } from '@angular/platform-browser';
...
constructor(private _sanitizer: DomSanitizer) { }
...
public settings = {
  columns: {
    checkbox: {
      title: 'Check Box',
      type: 'html',
      valuePrepareFunction: (value) => { return this._sanitizer.bypassSecurityTrustHtml(this.input); },
      filter: false
    },
  }
};
...
public input: string = '<input type="checkbox">/input>';

于 2018-03-13T14:52:59.543 回答