0

Inside ajax I want to create nested order list based on the xml data I use ajax to import. Below is what it should looks like.

i.food 
  a) sth
  b) another sth
ii. drink
  a) coke
  b) juice

To do this, I have the javascript below under $.ajax.

for(var k=0;k<categoryarray.length;k++){
  if(categoryarray[k][0]!==""){
    $('.cate ol').append("<li>"+categoryarray[k][1]+"<ol type='a' id="k???">"+"</ol>"+"</li>");
    for(var l=0;l<productarray.length;l++){
      if(categoryarray[k][0]==productarray[l][2]){
        $('#k???').append("<li>"+productarray[l][1]+"</li>");
                            }   
                        }
                    }
                }       

I think if I assign the corresponding k value to the ol tag as id, I should be able to append the corresponding products under categories based on categoryID as foreign key. Could anyone show me how to accomplish this? Many thanks!!

Sheikh Hasib
  • 7,423
  • 2
  • 25
  • 37
张剑桥
  • 67
  • 7
  • You can simply append them. `id=""+k` and `$('#'+k)` – BeeBee8 May 27 '18 at 15:22
  • @BhushanBabar Hi Bhushan! Thank you so much for replying! I have modified my codes to something like you said. However I am having another issue regarding nested order list. Do you mind help me have a look? https://stackoverflow.com/questions/50553453/nested-order-list-under-ajax – 张剑桥 May 27 '18 at 15:28

0 Answers0