var aid = "01012";
var flist = [
{
"attrCode": "01",
"processId": "98b756e5b318495ebb1f1dd74157ee22",
"fromId": "8EA42794B98E904AE050007F01005511a"
},
{
"attrCode": "0101",
"processId": "98b756e5b318495ebb1f1dd74157ee22",
"fromId": "8EA42794B98E904AE050007F01005511b"
},
{
"attrCode": "010201",
"processId": "98b756e5b318495ebb1f1dd74157ee22",
"fromId": "8EA42794B98E904AE050007F01005511c"
},
{
"attrCode": "02",
"processId": "ae0e661c2adb4591b341e03dcc901666",
"fromId": "5e94db3a3de0f477c2f4eab1c90a4f10d"
}
]
function test(aid, list) {
var fromId;
if (aid.length > 1 && !fromId) {
$.each(list, function (i, item) {
if (aid == item.attrCode) {
fromId = item.fromId
return false
} else {
test(aid.substr(0, aid.length - 1), list)
return
}
return false
})
}
return fromId;
}
console.log(999999999, test(aid, flist))
console