我在pickBy函数中传递一个数组作为参数
return fetch(API_BASE + url + (params ? '?' + stringify(pickBy(params, v=>v===false||!!v)) : ''), {
method: 'GET',
headers,
credentials: 'include'
}).then(resp=>{
authGuard(resp);
return resp;
});
而我的params对象是
currencyId: [12,44]
dueDateEnd: null
dueDateStart: null
exceptionTypeIds: (2) ["Contract updates/correction WIP", "Closed Contract"]
现在每当我只传递一个exceptionTypeIds然后它正在工作但是当我传递两个值时,它抛出的错误是exceptionTypeIds必须是一个字符串,CurrencyId必须是一个数字。每当我传递任何值时,我都希望实现它。
那真是怪了。我刚刚尝试使用lodash 4.14.120并且行为符合预期:
const params = {
currencyId: [12, 44],
dueDateEnd: null,
dueDateStart: null,
exceptionTypeIds: ["Contract updates/correction WIP", "Closed contract"]
}
console.log(_.pickBy(params, v => v === false || !!v))
回报
{
currencyId: [ 12, 44 ],
exceptionTypeIds: [ 'Contract updates/correction WIP', 'Closed contract' ]
}
即使只有一个exceptionTypeId或一个空数组:没有错误。
我在Node.js REPL中试过这个。也许浏览器中有一些东西。