Как обновить или перерисовать строки таблицы

Я попытался написать Object.assignDeep, который основан на пополнении Object.assign на mdn .

(ES5)

Object.assignDeep = function (target, varArgs) { // .length of function is 2
    'use strict';
    if (target == null) { // TypeError if undefined or null
        throw new TypeError('Cannot convert undefined or null to object');
    }

    var to = Object(target);

    for (var index = 1; index < arguments.length; index++) {
        var nextSource = arguments[index];

        if (nextSource != null) { // Skip over if undefined or null
            for (var nextKey in nextSource) {
                // Avoid bugs when hasOwnProperty is shadowed
                if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
                    if (typeof to[nextKey] === 'object' 
                        && to[nextKey] 
                        && typeof nextSource[nextKey] === 'object' 
                        && nextSource[nextKey]) {                        
                        Object.assignDeep(to[nextKey], nextSource[nextKey]);
                    } else {
                        to[nextKey] = nextSource[nextKey];
                    }
                }
            }
        }
    }
    return to;
};
console.log(Object.assignDeep({},{a:{b:{c:1,d:1}}},{a:{b:{c:2,e:2}}}))

3
задан mantelinga r 28 March 2019 в 05:36
поделиться

1 ответ

html code:

<div id="tableDIV">
  <table id="tableID">
    <thead>
      <tr>
        <th></th>
        <th></th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      if data exist
      loop{
      <tr>
        <td class="user-name"></td>
        <td></td>
        <td class="edit" data-user-id="">edit</td> //set user_id in attr data-user-id
      </tr>
      } // loops ends
      if close
    </tbody>
  </table>
</div>
<div id="noDataImageDiv"> No data image</div>

jquery code:

вы должны использовать событие щелчка на документе

$(document).on('click', '.edit', function () {
  var btn = $(this);
  var user_id = btn.attr("data-user-id"); //user_id of user will update
  // extra user data  
  $.ajax({
    method: "POST",
    url: url,
    data: {
      'id': id,
      // extra data to send
    },
    success: function (data) {
      if (data.status) // successfully user updated
      {
        var user = data.user;
        /* you can set user data like this */
        btn.closest('tr').find('.user-name').html(user.name);
      }
    }
  });
});
0
ответ дан Ravindra Patel 28 March 2019 в 05:36
поделиться
Другие вопросы по тегам:

Похожие вопросы: