0
我正尝试从XML文件创建动态HTML表格。在字母表的每个字母下有几个主要的“章节”。我想每个字母下将生成表格,类似这种格式:使用jQuery从XML文档创建表格
Code Description
Q87.1 Some description
F44.4 Another description
...
这里XML文件的样子:
<index>
<letter>
<title>A</title>
<mainTerm>
<title>Some description</title>
<code>Q87.1</code>
</mainTerm>
<mainTerm>
<title>Another description<nemod>(-some) (detail)</nemod></title>
<code>F44.4</code>
</mainTerm>
<mainTerm>
<title>A more detailed term</title>
<seeAlso>similar terms</seeAlso>
<term level="1">
<title>acute</title>
<code>R10.0</code>
</term>
<term level="1">
<title>angina</title>
<code>K55.1</code>
</term>
</mainTerm>
</letter>
.....
</index>
而且这里是jQuery代码我通过创建表与ID =“内容”一个div:
$(document).find("letter").each(function(){
// Define letters variable
$letters = $(this).find('> title').text();
//Find descendants of each letter
$codes = ($(this).find('code').text());
$desc = ($(this)).find('mainTerm title').text();
//Build table
$("#content").append(
'<table border="1"><tr><th>Code</th><th>Description</th></tr><tr><td> '+$codes+' </td><td> '+$desc+' </td></tr></table>'
);
(end brackets for the above)
我得到的输出是只有一行对每个字母/章节,所有的码表,所有的描述集中一起在一个单元中。
我需要的是一个动态表,其中每行都有一个单独的代码及其相应的描述。我怎么做?
非常感谢,@Bob尘!除了一个重要的细节之外,我明白了它的作用:XML结构偶尔会有更深的节点,我也想将它们分解成它们出现的单元格中的某种子表。例如,如果你看看上面结果中的最后一行,我们会得到“R10.0K55.1更详细的termacuteangina”。我希望能够将其显示为类似的表格格式,可能嵌套在显示“更详细的术语”的单元格中。不知道我是否确实如此清楚,但我充满希望:-) – Cucurigu
我明白了。让我试着处理更深层次的问题。 –
@Cucurigu,回复更新 –