NGRX/data 实体 getAll 将旧数据与新数据连接而不是更新
NGRX/data entity getAll concats old data with new instead of updating
我正在尝试使用 ngrx-data-lab 作为我项目的示例。
这是我使用的stackblitz项目。
我无法使用我正在使用的服务器的实际 url。 url 属于我的公司。但实际情况是服务器将随机生成的数据返回给应用程序。问题是商店中的实体没有被替换,而是被加起来。每次我刷新英雄页面时,服务器都会带来新数据并将其与旧数据连接起来。
在 entity-store.module.ts 中,我将 defaultDataServiceConfig root 和 Hero urls 更改为我的服务器。
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 总是会合并本地和远程实体。替换您必须使用负载的实体。
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);
}
我正在尝试使用 ngrx-data-lab 作为我项目的示例。
这是我使用的stackblitz项目。
我无法使用我正在使用的服务器的实际 url。 url 属于我的公司。但实际情况是服务器将随机生成的数据返回给应用程序。问题是商店中的实体没有被替换,而是被加起来。每次我刷新英雄页面时,服务器都会带来新数据并将其与旧数据连接起来。
在 entity-store.module.ts 中,我将 defaultDataServiceConfig root 和 Hero urls 更改为我的服务器。 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 总是会合并本地和远程实体。替换您必须使用负载的实体。
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);
}