Fix: revise code
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
class PlayerContent {
|
||||
class PlayerListRow {
|
||||
|
||||
constructor(playerID, playerName, enterCode) {
|
||||
constructor(playerID, playerName, enterCode, editButton, deleteButton) {
|
||||
this.playerID = playerID;
|
||||
this.playerName = playerName;
|
||||
this.enterCode = enterCode;
|
||||
this.editButton = editButton;
|
||||
this.deleteButton = deleteButton;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,14 +20,14 @@ class PlayerList {
|
||||
let id_list = parent.find(".player_id");
|
||||
// console.log(id_list);
|
||||
|
||||
this.playerContents = new Array();
|
||||
this.listRows = new Array();
|
||||
for(let i = 0; i < id_list.length; i++) {
|
||||
this.playerContents[i] = new PlayerContent(
|
||||
this.listRows[i] = new PlayerListRow(
|
||||
id_list[i], // span
|
||||
$(id_list[i]).siblings(".player_name"),
|
||||
$(id_list[i]).siblings(".player_entercode")
|
||||
// name_list[i + 1], // input
|
||||
// entercode_list[i + 1] // input
|
||||
$(id_list[i]).siblings(".player_entercode"),
|
||||
$(id_list[i]).siblings(".player_edit"),
|
||||
$(id_list[i]).siblings(".player_delete")
|
||||
);
|
||||
|
||||
$(id_list[i]).siblings(".player_edit").click(function() {
|
||||
@@ -35,7 +37,38 @@ class PlayerList {
|
||||
$(id_list[i]).siblings(".player_delete").click(function() {
|
||||
self.deletePlayer(this);
|
||||
})
|
||||
// console.log(this.playerContents[i].playerName.val());
|
||||
// console.log(this.listRows[i].playerName.val());
|
||||
// console.log(this.listRows[i]);
|
||||
}
|
||||
}
|
||||
|
||||
updatePlayerList(jsonData) {
|
||||
// console.log(jsonData);
|
||||
|
||||
for(let i = 0; i < 10; i++) {
|
||||
$(this.listRows[i].playerID).empty();
|
||||
|
||||
if(i < jsonData.length) {
|
||||
$(this.listRows[i].playerID).append(jsonData[i]["UserID"]);
|
||||
|
||||
$(this.listRows[i].playerName).val(jsonData[i]["Name"]);
|
||||
$(this.listRows[i].playerName).prop("disabled", false);
|
||||
|
||||
$(this.listRows[i].enterCode).val(jsonData[i]["EnterCode"]);
|
||||
$(this.listRows[i].enterCode).prop("disabled", false);
|
||||
|
||||
$(this.listRows[i].editButton).prop("disabled", false);
|
||||
$(this.listRows[i].deleteButton).prop("disabled", false);
|
||||
} else {
|
||||
$(this.listRows[i].playerName).val("");
|
||||
$(this.listRows[i].playerName).prop("disabled", true);
|
||||
|
||||
$(this.listRows[i].enterCode).val("");
|
||||
$(this.listRows[i].enterCode).prop("disabled", true);
|
||||
|
||||
$(this.listRows[i].editButton).prop("disabled", true);
|
||||
$(this.listRows[i].deleteButton).prop("disabled", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user