2017-06-02 74 views
0

如何在对象传递设定数组的从反应部件用于后请求:这应该是我的请求对象的结构:reactjs动作创作者传递数组

{ 
    "test": [ 
    "abc" 
    ], 
    "test2": [ 
    "def" 
    ], 
    "test3": [ 
    "sds" 
    ], 
    "name": "sam" 
} 

得到错误当我做:

阵营组件:

this.props.actioncreatorCall(
     someurl, 
     ["abc"], 
     ["def"], 
     ["sasd"], 
     "sam" 
    ); 

行动的创建者:

export function apiCAll(someurl,{test, test2, test3, name}) { 
return function dispatchUser(dispatch) { 
axios.post((url),{test, 
    test2, 
    test3, 
    name},{ }, 
).then((response) => { 
    dispatch({ 
     type: DATA_POST, 
     payload: response.data, 
    }); 
    browserHistory.push('/NEXTPAGE'); 
    }) 
    .catch(() => { 
    //SOME ERROR 
    }); 

}; }

回答

0

您需要在第二个参数去传递一个对象:

this.props.actioncreatorCall(someurl,{ 
    test: ["abc"], 
    test2: ["def"], 
    test3: ["sasd"], 
    name: "sam" 
}); 

你行动的创建者需要接受一个对象作为第二个PARAM:

export function actioncreatorCall(someurl, test = {}) {...} 
+0

非常感谢大通。真的很感激它。 – splendidDev