如何使用jquery从xml生成树结构。 [英] How can i generate tree structure from xml using jquery.
问题描述
大家好,
我是jquery的新手,我想知道以下信息
如何使用jquery从xml生成树结构。
i需要以下输出,使用jquery和xml
*测试
*儿童测试1
*儿童测试2
*测试
*儿童测试1
*儿童测试2
请给我一个解决方案。
感谢所有人。
我尝试了什么:
如何使用jquery从xml生成树结构。
Hi All,
I am new in jquery, i want to know the below information
How can i generate tree structure from xml using jquery.
i need the below output, using jquery and xml
* test
*child test1
*child test2
* testing
*child testing1
*child testing2
please drop me a solution for this.
thanks to all.
What I have tried:
How can i generate tree structure from xml using jquery.
推荐答案
请参阅我对该问题的评论。
到目前为止,我可以为您提供大部分答案。我不知道如何提供XML,但您可能需要从字符串解析XML,然后请阅读:解析和序列化XML - Web开发人员指南| MDN [ ^ ]。
我不知道树结构是什么意思,但如果你的意思是用HTML表示树的一些视觉表示,那就是你可以与jQuery一起使用:
DOM Insertion,Around | jQuery API文档 [ ^ ],
DOM插入,内部| jQuery API文档 [ ^ ],
DOM插入,外部| jQuery API文档 [ ^ ]。
树形可以用许多不同的方式显示,包括图形,我甚至不想在这里讨论,考虑到你问题的模糊性,只会提到可能性:HTML5 Canvas或SVG。但最简单的方法是使用缩进的常规文本,可以使用样式添加,例如
Please see my comment to the question.
So far, I can provide you with the most part of the answer. I don't know how the XML is supplied, but you may need to parse XML from a string, then please read this: Parsing and serializing XML — Web developer guides | MDN[^].
I don't know what do you mean by "tree structure", but if you mean some visual representation of a tree in HTML, this is what you can use with jQuery:
DOM Insertion, Around | jQuery API Documentation[^],
DOM Insertion, Inside | jQuery API Documentation[^],
DOM Insertion, Outside | jQuery API Documentation[^].
The tree shape could be shown in many different way, including graphical, which I don't even want to discuss here, considering the vagueness of your question, will just mention the possibilities: HTML5 Canvas or SVG. But the simplest way would be a regular text with indentation, which can be added using the styles, such as
myNode.style.marginLeft = currentLevel * indentationStep;
我希望你能掌握这个想法。同样,考虑到你问题的模糊性,我看不出哪些具体细节可能需要澄清;如果你到目前为止显示 你尝试了什么 ,我们可以讨论一些细节......太糟糕了,你没有写任何相关内容我试过的部分......
这篇关于如何使用jquery从xml生成树结构。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!