在发送 API 请求插入之前,我想检查该项目是否已经存在于商店中,如果没有,则仅发送插入请求。
add(){
const item = {id: 4,name:'test1',description:'description'}
// here i want to check whether test1 already exist or not
this.store.add(item);
this.httpService.insert(item).subscribe(
result => {
this.messageService.handleSuccess('inserted');
this.store.updateId(id, result.id);
},
error => this.messageService.handleError('error on insert:', error)
);
有人可以帮忙吗?
您可以使用查询:
add(){
const item = {id: 4,name:'test1',description:'description'}
if(query.hasEntity(4)) {
// exists
}
this.store.add(item);
this.httpService.insert(item).subscribe(
result => {
this.messageService.handleSuccess('inserted');
this.store.updateId(id, result.id);
},
error => this.messageService.handleError('error on insert:', error)
);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句