[英]How to update a data from a table using data-atributes in jQUery
I have this table in html and I need to update a user using the data-userid, I make I function that to this but this function didn't change anything in web page.我在 html 中有这个表,我需要使用 data-userid 更新用户,我让我对此进行了操作,但此功能没有更改网页中的任何内容。
Here, I have the html table code for data-userid:在这里,我有 data-userid 的 html 表代码:
<table id="tblList">
<tbody id="someTest">
<tr data-userid="801992084067"></tr>
<tr data-userid="451207954179"></tr>
<tr data-userid="310896831399"></tr>
<tr data-userid="863939754980"></tr>
<tr data-userid="1123542226482"></tr>
</tbody>
</table>
And here I have update function.在这里我有更新功能。
function updateUser(userId, user) {
var foundUser = findUser(userId);
foundUser.username = user.username;
foundUser.level = user.level;
foundUser.registrationStatus = user.registrationStatus;
foundUser.registrationDate = user.registrationDate;
for(var i = 1; i<userId.length; i++){
$("#someTest tr[data-userid = 'userid " + userId[i] + "']").each(function () {
// if (rowId === userId) {
var table = $('#tblList');
var row = "<tr data-userid=" + foundUser.id + ">"
+ " <td>"
+ " <img src='resources/img/edit.png' alt='Edit' class='btnEdit'/>"
+ " <img src='resources/img/delete.png' alt='deleteUser' class='btnDelete'/>"
+ "</td>"
+ " <td>" + foundUser.username + "</td>"
+ " <td>" + foundUser.level + "</td>"
+ " <td>" + foundUser.registrationStatus + "</td>"
+ " <td>" + foundUser.registrationDate + "</td>"
+ "</tr>";
table.append(row);
// }
});
}
hidePopup();
}
My question is the following: What to do in updateUser function because when I change a user, to see that change in browser?我的问题如下:在 updateUser 函数中该怎么做,因为当我更改用户时,要在浏览器中看到该更改?
try this尝试这个
function updateUser(userId, user) {
var foundUser = findUser(userId);
foundUser.username = user.username;
foundUser.level = user.level;
foundUser.registrationStatus = user.registrationStatus;
foundUser.registrationDate = user.registrationDate;
var row = " <td>"
+ " <img src='resources/img/edit.png' alt='Edit' class='btnEdit'/>"
+ " <img src='resources/img/delete.png' alt='deleteUser' class='btnDelete'/>"
+ "</td>"
+ " <td>" + foundUser.username + "</td>"
+ " <td>" + foundUser.level + "</td>"
+ " <td>" + foundUser.registrationStatus + "</td>"
+ " <td>" + foundUser.registrationDate + "</td>";
$("#someTest tr[data-userid = '" + userId + "']").html(row)
hidePopup();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.