我试图在 onBlur 函数中用逗号分割我的输入值,并将它们设置为数组的 redux 状态,但它不起作用。
我阅读了一些可能使用.split(',') 的主题
我的方法:
input onBlur={event = () => this.props.getValue(event.target.value)}
我的行动:
export const getValue = (value) => {
return dispatch => {
dispatch({
type: 'SET_VALUE',
payload: value.split(',')
});
};
};
我的减速机:
let initialState = {
codes: [],
};
export default (state = initialState, action) => {
switch (action.type) {
case SET_VALUE:
return { ...state, codes: action.payload };
default:
return state;
}
};
最后我想要什么?:
我想在我的减速器中像这样的数据:
codes: [28282, 28922, 18171, 27272, ....]
但它现在给了我这样的东西:
codes: [28282 28922 18171 27272 ....]