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
482 views
in Technique[技术] by (71.8m points)

javascript - Changing "key" and "values" into "name" and "children" using nest()

UPDATE: Solved thanks To @AmeliaBR, that answered my specific question here after I asked it.

  • This fiddle shows the adaptation of the solution to my specific problem.


My question was:

  • I'm looking for something like this without changing the structure of the functions I want to use.

  • This works great if you have defined parents inside the structure, but I can't get access to it.

What I ideally would do is to also do it work efficiently, and I think that in order to do so nest() might be a good answer.

I want to change

"key": "keyname", "values":"a value" 

into

"name": "keyname", "children":"a value"

And in the leaf node change (if possible making the rest of useless data dissapear)

 "value": "a value" 

into

"size": "a value"

I got a bit sad when I read this:

"I don't see any other method than going trough all elements recursively and changing names, which requires copying and deleting each field. However you can always use the source code of nest() as inspiration."

Can you beat that guy with your knowledge?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

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

...