javascript - ng2-smart-table 删除后不绑定(bind)

标签 javascript angular ng2-smart-table

我正在尝试使用 ng2-smart-table 来显示数据和内联编辑。但是,此组件似乎有问题。我克隆了 repo 并在本地运行了一些测试。我得到了基本示例演示并添加了输入数据对象以查看对象中的更改/绑定(bind):

<ng2-smart-table [settings]="settings" [source]="data"></ng2-smart-table>
<pre>{{data | json}}</pre>

当我“添加新”行时,它会按预期显示对象数组中的新条目。编辑任何行也可以,正确更新行。但是,当您删除一行时,该对象不会更改,并会继续在对象数组中显示已删除的行,但不会在网格中显示。当我尝试添加另一行时,它会在网格中显示新行,但不会更新/绑定(bind)对象数组中的新值。更新仍按预期工作。

我在 ng2-smart-table 的 github 上发布了这个问题,但我在那里没有得到答案,所以我希望我能在这里得到它。

所以这是一个真正的错误?这是 Plunker用我的测试。

谢谢大家

最佳答案

您必须刷新您传递给表的本地数据源。

我就是这样做的。

HTML

<ng2-smart-table 
    [settings]="itemTableSettings"
    [source]="itemSource" 
    (deleteConfirm)="onDeleteConfirm($event)">
</ng2-smart-table>

typescript 代码

import {LocalDataSource} from 'ng2-smart-table';

items: Item[];
itemSource: LocalDataSource;

itemTableSettings = {
    delete: {
      confirmDelete: true
    },
    columns: {...}
}

constructor() {}

ngOnInit() {
    this.itemSource = new LocalDataSource(this.items);
}

onDeleteConfirm(event) {

    // Delete item from array
    let index = this.items.indexOf(event.data);
    console.log(index);
    this.items.splice(index, 1);

    // Update the array in the service class


    // Update the local datasource
    this.itemSource = new LocalDataSource(this.items);
}

为我工作。

关于javascript - ng2-smart-table 删除后不绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45848163/

相关文章:

javascript - CKEditor 奇怪的样式改变行为

javascript - 键盘事件如何触发兄弟按钮的点击事件? (里面的jsfiddle)

javascript - 从 Eloquent Javascript 返回 null

javascript - 返回值与文件内容头相关

javascript - 如何获取/获取函数的所有参数?

javascript - 为什么要使用 observables 而不是 Ajax?

html - 图像未在 Angular 2 中加载

node.js - Angular 6 - 删除node_module包并将其用于本地项目更改

javascript - ng2-smart-table如何更改自定义按钮在点击时的显示和隐藏

angularjs - Angular 2通过服务器API加载数据: data.切片错误