我正在尝试使用 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/