【问题标题】:ng-2-smart-table checkbox checked or not depending on value of columnng-2-smart-table 复选框是否选中取决于列的值
【发布时间】: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>

我该怎么做?提前致谢。

【问题讨论】:

  • 你只是在寻找类似&lt;input [(ngModel)]="checkboxValue" type="checkbox" name="checkbox"&gt;的东西吗?
  • 也许可以,但是如何将其映射到 ng-2-smart-table 的源数据对象?

标签: angular ng2-smart-table


【解决方案1】:

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-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-03
    • 2018-11-13
    • 1970-01-01
    相关资源
    最近更新 更多