gpt4 book ai didi

angular - NGRX/数据实体 getAll 将旧数据与新数据连接而不是更新

转载 作者:行者123 更新时间:2023-12-05 08:31:25 25 4
gpt4 key购买 nike

我正在尝试使用 ngrx-data-lab作为我的项目的示例。

这是 stackblitz我使用的项目。

我不能使用我正在使用的服务器的实际 url。该网址属于我的公司。但实际情况是服务器将随机生成的数据返回给应用程序。问题是商店中的实体没有被替换,而是被加起来。每次我刷新英雄页面时,服务器都会带来新数据并将其与旧数据连接起来。

entity-store.module.ts 中,我将 defaultDataServiceConfig root 和 Hero url 更改为我的服务器。getAll() 有效,但正如我再次说过的那样,它将数据连接到旧数据。

  root: 'api', // default root path to the server's web api

// Optionally specify resource URLS for HTTP calls
entityHttpResourceUrls: {
// Case matters. Match the case of the entity name.
Hero: {
// You must specify the root as part of the resource URL.
entityResourceUrl: 'api/hero/',
collectionResourceUrl: 'api/heroes/'
}
},

如何让 getAll 替换旧数据而不是合并它?

最佳答案

我的错。多次重新创建我的项目后。我发现 getAll 总是会合并本地和远程实体。替换您必须使用负载的实体。

获取全部

  /**
* Dispatch action to query remote storage for all entities and
* merge the queried entities into the cached collection.
* @param [options] options that influence merge behavior
* @returns Observable of the collection
* after server reports successful query or the query error.
* @see load()
*/
getAll(options?: EntityActionOptions): Observable<T[]> {
return this.dispatcher.getAll(options);
}

加载

  /**
* Dispatch action to query remote storage for all entities and
* completely replace the cached collection with the queried entities.
* @param [options] options that influence load behavior
* @returns Observable of the collection
* after server reports successful query or the query error.
* @see getAll
*/
load(options?: EntityActionOptions): Observable<T[]> {
return this.dispatcher.load(options);
}

关于angular - NGRX/数据实体 getAll 将旧数据与新数据连接而不是更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58553658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com