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');
      });
    });
  • 相关阅读:
    将表中数据生成SQL语句
    遍历页面所有的控件
    MSN不能登陆
    刷新框架页
    JS传参出现乱码
    iframe攻击
    有关于VS调试Javascript的问题
    C#中StringBuilder类的使用
    前瞻XAML
    Asp.Net在SqlServer中的图片存取
  • 原文地址:https://www.cnblogs.com/Answer1215/p/3928426.html
Copyright © 2011-2022 走看看