我在这个选择器上的过滤方法有什么问题?
What is wrong with my filter method on this selector?
它总是return一个空数组。
它应该只有 return 个 ID 和标题,其中 drawsTRFormIdAndTitleSelector 的 ID 是 === drawTRSelector
的 transactionRequestFormId
export const idAndTitleSelector = createSelector(
drawTRSelector,
drawsTRFormIdAndTitleSelector,
(transactionRequests, idAndTitle) =>
idAndTitle.filter(
({ id }) => id === transactionRequests.transactionRequestFormId
)
);
drawTRSelector return 是一个 objects 的数组,如下所示:
[{
id: "1",
number: "1",
transactionRequestFormId: "1",
}]
drawsTRFormIdAndTitleSelector return 是一个 objects 的数组,如下所示:
[{
id: "1",
title: "TR All Others",
}]
我想你想做这样的事情:
const drawTRSelectorIds = createSelector(
[drawTRSelector],
(items) => items.map(({ id }) => id)
);
export const idAndTitleSelector = createSelector(
drawTRSelectorIds,
drawsTRFormIdAndTitleSelector,
(ids, idAndTitle) =>
idAndTitle.filter(({ id }) => ids.includes(id))
);
它总是return一个空数组。 它应该只有 return 个 ID 和标题,其中 drawsTRFormIdAndTitleSelector 的 ID 是 === drawTRSelector
的 transactionRequestFormIdexport const idAndTitleSelector = createSelector(
drawTRSelector,
drawsTRFormIdAndTitleSelector,
(transactionRequests, idAndTitle) =>
idAndTitle.filter(
({ id }) => id === transactionRequests.transactionRequestFormId
)
);
drawTRSelector return 是一个 objects 的数组,如下所示:
[{
id: "1",
number: "1",
transactionRequestFormId: "1",
}]
drawsTRFormIdAndTitleSelector return 是一个 objects 的数组,如下所示:
[{
id: "1",
title: "TR All Others",
}]
我想你想做这样的事情:
const drawTRSelectorIds = createSelector(
[drawTRSelector],
(items) => items.map(({ id }) => id)
);
export const idAndTitleSelector = createSelector(
drawTRSelectorIds,
drawsTRFormIdAndTitleSelector,
(ids, idAndTitle) =>
idAndTitle.filter(({ id }) => ids.includes(id))
);