如何避免秋田商店中的重复条目?
how to avoid duplicate entries in akita store?
在发送 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)
);
在发送 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)
);