我定义了一个从数组中删除项目的操作:
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
,它仍然不会更新我的列表,直到我触发一些其他操作(单击、重命名等),在这种情况下,我将能够看到该项目已被删除。
我错过了什么吗?
尝试这个解决方案:
@action deleteItem = async (target) => {
try {
await backendService.deleteItem(target.id);
runInAction(() => {
this.items = this.items.filter(item === target);
});
} catch (error) {
...
}
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)