jQuery Mobile从ParsedXML()文件嵌套UL显示最后一个条目



我有一个简单的xml文件,其中包含姓名、地址、职称等信息。。。我想用jquery parseXML()解析这个文件,然后在嵌套列表中显示它的内容。我有一个这样的功能:

function parseXml(xml)
    { 
      $(xml).find("Employee").each(function()
      {
        $("#output").append("<li><h3>" + $(this).find("name").text()+ "</h3><p>"
                      + $(this).find("jobtitle").text() + "</p>" +  
                      "<ul><li>"+$(this).find("address").text() + 
                      "</li><li>"+$(this).find("workphone").text() + 
                      "</li><li>"+$(this).find("homephone").text() + 
                      "</li><li>"+$(this).find("cellphone").text() +
                      "</li><li>"+$(this).find("fax").text() +
                      "</li><li>"+$(this).find("contractor").text() +
                      "</li></ul></li>"
        );
        $("#output").listview("refresh");
      });
    }

将信息放入第一个列表是没有问题的。但是,第二个UL(嵌套的UL)没有正确显示。主要是当我点击父LI时,文档中的最后一个xml条目显示为嵌套的LI,格式不正确。所有内容都垂直地挤在屏幕上。

我的xml看起来是这样的:

<Employee>
        <name>Jon</name>
        <email>jon@email.com</email>
        <jobtitle>Software Engineer</jobtitle>
        <address>123 City Street</address>
        <workphone>555-555-5555</workphone>
        <homephone>555-555-5551</homephone>
        <cellphone>555-555-5552</cellphone>
        <fax>555-555-5553</fax>
    </Employee>
    <Employee>
        <name>Don</name>
        <email>don@email.com</email>
        <jobtitle>Software Man</jobtitle>
        <address>555 City Street</address>
        <workphone>222-222-2222</workphone>
        <homephone>222-222-2224</homephone>
        <cellphone>222-222-2226</cellphone>
        <fax>222-222-2228</fax>
    </Employee>
    <Employee>
        <name>Juan</name>
        <email>juan@email.com</email>
        <jobtitle>IT Specialist</jobtitle>
        <address>888 City Street</address>
        <workphone>777-878-7878</workphone>
        <homephone>777-888-7878</homephone>
        <cellphone>777-777-7878</cellphone>
        <fax>777-878-7898</fax>
    </Employee>

有人有更好的方法在嵌套列表中显示这个xml文件吗?我喜欢Jquery Mobile只创建嵌套列表的方式,它将父级变成嵌套LI的链接。

此处回答:jQuery分析jQuery Mobile列表中的XML显示UL UL返回仅XML 中的最后一项

my.listview("刷新");需要在每个的外面。

最新更新