简体   繁体   English

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

[英]jQuery Mobile Nested UL from ParsedXML() file Showing Last entry

I have a simple xml file that contains information such as name, address, job title... I would like to parse this file with jquery parseXML() and then display its content in a nested list. 我有一个简单的xml文件,其中包含诸如名称,地址,职位等信息。我想使用jquery parseXML()解析此文件,然后在嵌套列表中显示其内容。 I have a function like so: 我有一个像这样的功能:

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");
      });
    }

... that gets the information into the first list no problem. ...将信息放入第一个列表中没问题。 However, the second UL, the nested UL, isn't displaying correctly. 但是,第二个UL(嵌套的UL)无法正确显示。 Mainly when I click on the parent LI, the final xml entry in the document shows up, badly formated, as the nested LI. 主要是当我单击父LI时,文档中的最终xml条目显示为格式错误的嵌套LI,格式错误。 Everything is crammed together vertically on the screen. 一切都在屏幕上垂直塞满。

My xml looks like so: 我的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>

Anyone have a better way to display this xml file within a nested list? 有人有更好的方法在嵌套列表中显示此xml文件吗? I like the Jquery Mobile way of just creating the nested list and it turns the parent into a link to the nested LI. 我喜欢仅使用Jquery Mobile创建嵌套列表的方式,它将父代转换为指向嵌套LI的链接。

Answered here: jQuery Parse XML display in jQuery Mobile list UL UL returning last item in XML only 在这里回答: jQuery解析jQuery Mobile列表中的XML显示UL UL仅返回XML中的最后一项

my .listview("refresh"); 我的.listview(“刷新”); needed to be OUTSIDE of the each. 需要在每个之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM