繁体   English   中英

使用 ngx-datatable 中的 ngIf 补充布尔值不起作用

[英]Complementing of boolean not working, with ngIf in ngx-datatable

onSelect() is called whenever a row in ngx-datatable is selected. isNodeSelected由于某种原因在选择同一行时没有得到补充,即使它进入了 if 语句。 isNodeSelectedngIf一起使用来显示按钮。 Webstorm 突出了补充语句并说“缩小到真实”

onSelect({ selected }) {
    this.isNodeSelected = true;
    if (Array.isArray(this.selected) && this.selected.length === 1) {
      if (this.selected[0].hasOwnProperty('id') && this.selected[0].id === selected[0].id) {
        this.isNodeSelected = !this.isNodeSelected;
      } else if (this.selected[0].hasOwnProperty('id') && this.selected[0].id !== selected[0].id) {
        this.selected = selected;
        this.isNodeSelected = true;
      }
    } else {
      this.selected = selected;
      this.isNodeSelected = true;
    }
  }

如果这个函数在你的 component.ts 文件中,那么至少你需要替换:

onSelect({ selected }) {

onSelect(selected) {

因为大括号用于在模板中插入变量值,而不是在后面的代码中。

除此之外,使用调试器逐步检查每一位以检查每个点的值。

例如,它是否进入第二个 if 语句,如果是,则 selected[0].id 等的值是多少?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM