开发者

bloated jquery xml requests

开发者 https://www.devze.com 2023-01-31 10:14 出处:网络
I was wondering if anyone had an alternative to this. $(xml).find(\"a\").each(function(){ $(this).find(\'b\').each(function(){

I was wondering if anyone had an alternative to this.

          $(xml).find("a").each(function(){
           $(this).find('b').each(function(){
               $(this).find('c').each(function(){
                   $(this).find('d1').each(function(){
                        sectionValidation.RegisterTerms.setRegisterTermsArray(this);
                   });
                    $(this).find('d2').each(function(){
                        sectionValidation.RegisterTerms.checkValidVariations(this, val);
                    });
               });
           });
       });

It seems really bloated and there has to be a more elegant 开发者_开发问答approach to getting nested xml data. Thank you


You can at least combine your a through c selector with a decendant selector (space in-between), like this:

$(xml).find("a b c").each(function(){
  $(this).find('d1').each(function(){
      sectionValidation.RegisterTerms.setRegisterTermsArray(this);
  });
  $(this).find('d2').each(function(){
      sectionValidation.RegisterTerms.checkValidVariations(this, val);
  });
});

For the other, it depends on the size of the document as to if this would be faster:

var $xml = $(xml);
xml.find("a b c d1").each(function(){
  sectionValidation.RegisterTerms.setRegisterTermsArray(this);
});
xml.find("a b c d2").each(function(){
  sectionValidation.RegisterTerms.checkValidVariations(this, val);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消