angular - 在商店中拉取 Ngrx 实体的问题
问题描述
我一直在开发一个应用程序来学习 Angular Ngrx 商店和实体。该应用程序使用来自 ngrx/platform 的示例应用程序作为起点。代码和应用程序在 StackBlitz 上
我正在尝试使用 createSelector 过滤掉具有与所选任务的 id 匹配的 task_id 的 pomos。甚至无法做到这一点,我尝试使用基于 EntityAdapter 的 pomo reducer 将所有 pomos 加载到 state 中。那也行不通。我的所有操作都成功了,包括向商店添加了一个 pomo,但我无法加载它们。在这一点上,我只是想让它们全部加载,但最终目标是一个选择器,它根据它的 task_id 加载 pomos。我怀疑这个问题很可能是国家实际上是如何组成的,但我不知道该怎么做。就像我说的,将 Pomo 添加到商店的操作可以正常工作,但是在加载 pomo 时。它返回空。
这是我的减速器/index.ts
export interface State {
search: fromSearch.State;
tasks: fromTasks.State;
pomos: fromPomos.State;
collection: fromCollection.State;
}
export const reducers: ActionReducerMap<any> = {
search: fromSearch.reducer,
tasks: fromTasks.reducer,
pomos: fromPomos.reducer,
collection: fromCollection.reducer,
};
export const getTasksState = createFeatureSelector<TasksState>('tasks');
export const getPomosState = createSelector(getTasksState, state => state.pomos);
export const getTaskEntitiesState = createSelector(
getTasksState,
state => state.tasks
);
export const getPomosEntitiesState = createSelector(
getTasksState,
state => state.pomos
);
export const {
selectIds: getTaskIds,
selectEntities: getTaskEntities,
selectAll: getAllTasks,
selectTotal: getTotalTasks,
} = fromTasks.adapter.getSelectors(getTaskEntitiesState);
export const {
selectIds: getPomoIds,
selectEntities: getPomoEntities,
selectAll: getAllPomos,
selectTotal: getTotalPomos,
} = fromPomos.adapter.getSelectors(getPomosEntitiesState);
解决方案
推荐阅读
- flutter - flutter_webrtc :如何在 visio 期间向对等方发送短信
- c# - 如何修复“项目 'ListView1' 加载失败:[MSB4236] 找不到指定的 SDK 'Microsoft.NET.Sdk'。”在带有 Xamarin.Forms 的 Rider 上
- php - 用 .htaccess 重写 URL 到 PHP 路由器
- typescript - 如何在页面加载之前加载用户
- html - 为什么整个图像不适合块?
- c++ - 无法在 C++ (cpp) 中使用 ifstream 读取 txt 文件
- python - 如何检查列是否包含列表
- javascript - 等待功能完成后再继续
- reactjs - 如何使元素正确重置其状态并在专注于输入的同时传递道具
- python - FastAPI 端点未接收到发布数据