我正在使用下划线数组迭代器来操作对象。结果应该需要作为单次返回,但我得到了多次,就像我的数组长度一样。如何纠正这个?
这是我的功能:
var ValidPaths = {
"green":{
"url":"greenController.js",
"lightgreen" :{
"url":"lightGreenController.js",
"floragreen":{
"url":"floragreenController.js",
"ultragreen":{
"url":"floragreenController.js",
}
}
}
}
}
var path = "green",
subPath = 'lightgreen/floragreen';
var paths = [path].concat(subPath.split('/')),
arr = [],prePath=ValidPaths;
function pathFinder (path,i){
if(prePath[path]){
arr.push({"label":path,"url":prePath[path]['url']});
prePath = prePath[path];
} else{
console.log("there is no path like " + path + "in ValidPaths");
}
return arr;
}
var breadCrumb = _.map(paths, function(root,i){
return pathFinder(root,i);
});
console.log("breadCrumb", breadCrumb); // giving me 3 arrays instead 1 how to solve this?