var updateIconPathRecorsive = function (item) {
if (item.iconSrc) {
item.iconSrcFullpath = 'some value..';
}
_.each(item.items, updateIconPathRecorsive);
};
updateIconPathRecorsive(json);
有没有一种不使用函数的更好方法? 我不想将函数从调用中移开,因为它就像一个复杂的for循环。我可能希望能够写出类似以下的内容:
_.recursive(json, {children: 'items'}, function (item) {
if (item.iconSrc) {
item.iconSrcFullpath = 'some value..';
}
});