给定,我有一个数组
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
传递给调度即可。将在减速器中处理
var myKey = "myObjectKey";
var anArray = ["apple", "balloon", "dog", "cat"];
store.dispatch({type: 'ADD_ITEM', payload: { [myKey]: anArray} })
关于javascript - Redux中具有动态键的对象内部的数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39769431/