【发布时间】:2017-07-21 08:29:17
【问题描述】:
我有一组错误代码,我必须为其显示自定义消息。我正在尝试使用 lodash startsWith 函数查找匹配错误。在codepen中尝试过这个并得到未定义。请问你能帮忙吗?
// An array, object or any data (eg. from an ajax call)
let errorCodes = ['ErrorCode1', 'ErrorCode2', 'ErrorCode3', 'ErrorCode4', 'ErrorCodeBusiness']
let response = {
meta:
{
version: "1.0",
time: "2017-07-20 08:28 AM GMT"
},
errors:
{
errors:
[
{
id: null,
code: "ErrorCodeBusiness",
message: "",
uuid: ""
}
],
warnings: null
}
};
//Find the error code that starts with given set of errors
const hasError = _.find(response.errors.erorrs, (error) => {
_.some(errorCodes, (code) => _.startsWith(code,error.code))
})
console.log(hasError);
【问题讨论】:
标签: javascript ecmascript-6 lodash