如何避免秋田商店中的重复条目?

在发送 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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章