代码之家  ›  专栏  ›  技术社区  ›  Dan.StackOverflow

jquery嵌套了每个问题

  •  1
  • Dan.StackOverflow  · 技术社区  · 17 年前

    请参阅下面的编辑。 我正试图让一些jquery在我正在构建的wordpress插件中工作。(在wordpress中使用jQuery时,使用字符串“jQuery”而不是“$”习惯用法,请注意)

    示例xml:

       <person>
            <Name>Some Name</Name>
            <location>
                <locationName>One Address</locationName>
            </location>
            <date>
                <startDate>01-01-09</startDate>
            </date>
        </person>
    

    jQuery(text).find("person").each(function(){
        jQuery("#active_list")
            .append(
                "<div id=\'Entry\'>"
                + jQuery(this).find("Name").text()
                + "<b> at </b>"
        ;
    
        jQuery(this)
            .find("location")
            .each(function(){
                jQuery("#active_list")
                    .append(
                        jQuery(this).find("locationName").text()
                        + " <b> on </b>"
                    )
                ;
            })
        ;
    
        jQuery("#active_list")
            .append(
                jQuery(this).find("date").find("startDate").text()
                + "</div>"
            )
        ;
    });
    

    <div id="Entry"> Some Name<b> at </b></div>One Address <b> on </b>01-01-09
    

    jQuery("#active_list").append("<div id=\'ActivityEntry\'>");
    

    在它自己的行中,它随后立即关闭div。所以我想我需要用jquery构建一个div元素,然后打包它,然后附加我的div元素。

    2 回复  |  直到 17 年前
        1
  •  3
  •   cdmckay    17 年前

    (function($) {
    
        ... (code with $) ...
    
    })(jQuery);
    

    each this :

    $(...).each(function(i, val1) { 
    
        $(...).each(function(j, val2) { ... }
    
    });
    

    并使用 val1 val2 .

        2
  •  2
  •   WEFX venkateswararao    14 年前

    jQuery(text).find("person").each(function(){
       var html;
       html = jQuery(this).find("Name").text() + "<b> at </b>";
    
       jQuery(this).find("location").each(function(){
          html += jQuery(this).find("locationName").text() + " <b> on </b>";
       });
    
       html += jQuery(this).find("date").find("startDate").text();
       jQuery("#active_list").append("<div id=\'Entry\'>" + html + "</div>");
    });