zoukankan      html  css  js  c++  java
  • [jQuery] $.map, $.each, detach() , $.getJSOIN()

    $.map function will return the modifies array.

    $.each function will not new a new array, the old value will still be the same.

    detach() funciton will remove the element from the DOM, you can append those element later, it works more eiffient.

    getJSON

    $('button').on('click', function() {
      $.getJSON('/cities/deals', function(result){
          $.each(result, function(index, dealItem) {
            var dealElement = $('.deal-' + index);
            dealElement.find('.name').html(dealItem.name);
            dealElement.find('.price').html(dealItem.price);
          });
      });
    });

    Let's take a minute to make our previous code a bit more efficient. Use the .detach() method to remove the .flight-times list element from the DOM before you insert the new listitems. Then, re-insert the .flight-times element back into the .flights element.

    $('.update-available-flights').on('click', function() {
      $.getJSON('/flights/late', function(result) {
        var flightElements = $.map(result, function(flightItem, index){
          var flightEl = $('<li>'+flightItem.flightNumber+'-'+flightItem.time+'</li>');
          return flightEl;
        });
        $('.flight-times').detach().html(flightElements).appendTo('.flights');
      });
    });
  • 相关阅读:
    OSCP Learning Notes Exploit(7)
    正则表达式中?=和?:和?!的理解
    提取日志中的ip
    ip地址的正则表达式
    linux内核tmpfs/shmem浅析
    记一个linux内核内存提权问题
    linux内存屏障浅析
    linux IPv4报文处理浅析
    linux会话浅析
    linux memory lock浅析
  • 原文地址:https://www.cnblogs.com/Answer1215/p/3928426.html
Copyright © 2011-2022 走看看