我正在开发一个使用 Redux 来管理状态的 React-Native 移动应用程序。我有过滤器来管理显示的数据。
我正在使用 Redux 来管理过滤器中的所有数据。
这很简单:我点击复选框,它就会被点击。我再次单击该复选框(猜猜是什么),它没有被单击。当存在值为“allInclusive”的框时,除“allInclusive”以外的所有框均未选中。
这是减速器的代码和复选框的代码。
var comparators = {...state.comparators};
if (!comparators[action.payload.comparator]) {
comparators[action.payload.comparator] = {};
comparators[action.payload.comparator][action.payload.name] = [action.payload.value];
} else {
if (!comparators[action.payload.comparator][action.payload.name]) {
comparators[action.payload.comparator][action.payload.name] = [action.payload.value];
} else {
if (comparators[action.payload.comparator][action.payload.name].includes(action.payload.value)) {
comparators[action.payload.comparator][action.payload.name] = comparators[action.payload.comparator][action.payload.name].filter(value => value !== action.payload.value);
} else {
comparators[action.payload.comparator][action.payload.name].push(action.payload.value);
}
}
}
return Object.assign({}, state, {
comparators,
});
慕丝7291255
慕沐林林
相关分类