Redux 中具有动态键的对象内的数组

Array inside an Object with Dynamic Key in Redux

给定,我有一个数组

var myKey = "myObjectKey";
var anArray = ["apple", "balloon", "dog", "cat"];

anArray.map(function(thing) {
  store.dispatch(Object.assign({type: 'ADD_ITEM', payload: thing, key: myKey}));
});

如何获得以下输出?

store.getState();
# Object: {myObjectKey: ["apple", "balloon", "dog", "cat"]}

这应该有效。只需将 object 传递给调度即可。会在reducer中处理

var myKey = "myObjectKey";
var anArray = ["apple", "balloon", "dog", "cat"];

  store.dispatch({type: 'ADD_ITEM', payload: { [myKey]: anArray} })