Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

javascript - 如何显示此列表结构? 角度的(How can I show this list structure? Angular)

'Picture a' is the data I get from the AJAX call.(“图片a”是我从AJAX调用中获得的数据。)

When a task has 'dependencyTaskId' which is equal to another task's ID, it becomes the child of that task.(当一个任务的“ dependencyTaskId”等于另一个任务的ID时,它将成为该任务的子代。) If 'dependencyTaskId' is null, that task will be at top level.(如果'dependencyTaskId'为null,则该任务将处于顶层。) The end results will show a tree structure of all the tasks ('picture b').(最终结果将显示所有任务的树形结构(“图片b”)。) I am using Angular 6. How can I achieve this?(我正在使用Angular6。如何实现?) Please help me.(请帮我。) Thanks a lot.(非常感谢。) 在此处输入图片说明 在此处输入图片说明   ask by Mark translate from so

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

1 Reply

0 votes
by (71.8m points)

You must try this via frontend side:(您必须通过前端尝试此操作:)

const nestedChild = (itemArray, dependancyTaskId = null) => { const responseArray = [] for(let i in itemArray) { if(itemArray[i].dependancyTaskId == dependancyTaskId) { const children = nestedChild(itemArray, itemArray[i].taskId) if(children.length) { itemArray[i].children = children } responseArray.push(itemArray[i]) } } return responseArray } const response = nestedChild(tasks); Now you can traverse and print it in unordered list and can format it via css.(现在,您可以遍历并将其打印在无序列表中,并可以通过CSS对其进行格式化。) Hope this will help you much.(希望这对您有帮助。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...