【发布时间】:2022-09-30 21:13:56
【问题描述】:
我有一个这样的对象:
const params = {
\'userId[]\': [1, 2],
\'empId\': 2,
advance: \'hello\',
};
我想做一个这样的字符串:
userId[]=1&userId[]=2&empId=2&advance=hello
我正在尝试这样:
const myResult = Object.entries(params)
.map(([key, value]) => {
if (Array.isArray(value)) {
let result;
value.forEach(item => {
`${key}=${value}`
})
return result
}
// return
})
.join(\'&\');
console.log(myResult);
但无法弄清楚下一步该做什么。
-
您的参数有 empId = 2,但您想要的字符串有 empId = 5?这是一个错字吗?
-
@caTS 是的,这是拼写错误。对不起
-
***.com/a/47164688/4826457 Angular 使用
HttpParams
对象来构建 URL 参数