Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
812 views
in Technique[技术] by (71.8m points)

递归获取树形数据总是莫名其妙调用多余数据

如图:树形数据结构为:
image.png
image.png
简单的说就是每一层带一个children数据,里面有和上一层结构一样的数组数据;

然后有一组数据如:
image.png

里面的数字对应树形数据中的dict_code值;

然后我是用递归思想想遍历对应的dict_name值;

如图:
image.png

但是总是输出:
image.png

原因是在获取对应的dict_name以后调用函数没有停止,继续执行导致,有没有知道怎么写才能正确输出dict_name的朋友呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

这需要加return吧

if(arr[i].children) return recursionChild(val,arr[i].children)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...