How to generate UL Li list from string array using jquery?

前端 未结 7 1145
盖世英雄少女心
盖世英雄少女心 2020-12-04 19:25

I have string array like

\'United States\', \'Canada\', \'Argentina\', \'Armenia\', \'Aruba\', \'Australia\', \'Austria\', \'Azerbaijan\', \'Bahama

相关标签:
7条回答
  • 2020-12-04 20:07

    Other variation of Abhishek Bhalani: You can use Array.map() instead of $.each()

    var items = ['United States', 'Canada', 'Argentina', 'Armenia'];
    var cList = $('ul.mylist');
    items.map( (item,i ) => {
          var li = $('<li/>')
            .addClass('ui-menu-item')
            .attr('role', 'menuitem')
            .appendTo(cList);
          $('<a class="ui-all">'+ i + ': ' + item.name + '<a/>')
            .appendTo(li);
        });
    
    0 讨论(0)
提交回复
热议问题