入參的結構:http://{domain}/api/getRoleAll?userName={xxx}&roleList={x}&roleList={x};
採用字符串拼接的形式
const { roleAll } = this.props.storeData;
// 篩選所有選中的多選框
const selectRole = roleAll.filter(item => item.selected);
// 存到數組裏並遍歷該數組
let arrRoleId = []
selectRole.forEach(item => {
arrRoleId.push({roleId: item.roleId})
});
// 字符串拼接
let str = `userName=${this.state.updateName}&`;
arrRoleId.forEach(item => {
str += `roleList=${item.roleId}&`
})
// 把最後一個&截取掉
str=str.substring(0, str.length-1);
// 觸發dispatch,把字符串傳到saga
dispatch({
type: 'updateUserRole',
userName: str
})