Support array parameter parsing (#4300)
This commit is contained in:
parent
617e594d8d
commit
6d2de002ef
|
|
@ -20,14 +20,19 @@ export function getPopupContainer(node?: HTMLElement): HTMLElement {
|
||||||
* @param obj
|
* @param obj
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
* eg:
|
* eg:
|
||||||
* let obj = {a: '3', b: '4'}
|
* let obj = {a: '3', b: '4', c: ['1','2']}
|
||||||
* setObjToUrlParams('www.baidu.com', obj)
|
* setObjToUrlParams('www.baidu.com', obj)
|
||||||
* ==>www.baidu.com?a=3&b=4
|
* ==>www.baidu.com?a=3&b=4&c=1,2
|
||||||
*/
|
*/
|
||||||
export function setObjToUrlParams(baseUrl: string, obj: any): string {
|
export function setObjToUrlParams(baseUrl: string, obj: any): string {
|
||||||
let parameters = '';
|
let parameters = '';
|
||||||
for (const key in obj) {
|
for (const key in obj) {
|
||||||
parameters += key + '=' + encodeURIComponent(obj[key]) + '&';
|
const value = obj[key];
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
parameters += `${key}=${encodeURIComponent(value.join(','))}&`;
|
||||||
|
} else {
|
||||||
|
parameters += `${key}=${encodeURIComponent(value)}&`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
parameters = parameters.replace(/&$/, '');
|
parameters = parameters.replace(/&$/, '');
|
||||||
return /\?$/.test(baseUrl) ? baseUrl + parameters : baseUrl.replace(/\/?$/, '?') + parameters;
|
return /\?$/.test(baseUrl) ? baseUrl + parameters : baseUrl.replace(/\/?$/, '?') + parameters;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue