【发布时间】:2020-01-09 16:08:01
【问题描述】:
我已经定义了一个从数组中删除项目的操作:
export default class myStore {
@observable items = [];
...
...
@action deleteItem = async (target) => {
try {
await backendService.deleteItem(target.id);
runInAction(() => {
const targetIndex = this.items.indexOf(target);
this.items.splice(targetIndex, 1);
});
} catch (error) {
...
}
};
...
...
}
尽管我将组件设为observer,但在我触发其他一些操作(单击、重命名等)之前,它仍然不会更新我的列表,在这种情况下,我将能够看到该项目已被删除。
我错过了什么吗?
【问题讨论】:
-
console.log(targetIndex);在 const targetIndex = this.items.indexOf(target); 之后
-
@Jackkobec 它给了我正确的索引(例如 3)。如果我手动刷新它或执行一些其他操作,它会正确更新列表。这不是实时的(未观察到)
标签: javascript arrays react-native mobx mobx-react