重写删除表格行的方法

This commit is contained in:
falcon 2020-05-20 15:07:05 +08:00
parent 57554f1ae3
commit 078aaa0188
2 changed files with 8 additions and 22 deletions

View File

@ -15,11 +15,11 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="r in rows"> <tr v-for="(r,i) in rows">
<td>{{r.Id}}</td> <td>{{r.Id}}</td>
<td>{{r.Name}}</td> <td>{{r.Name}}</td>
<td>{{r.Description}}</td> <td>{{r.Description}}</td>
<td><input type="button" value="删除" v-on:click="remove(r.Id)" /></td> <td><input type="button" value="删除" v-on:click="remove(r.Id,i)" /></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -51,18 +51,10 @@
}); });
} }
}, },
remove(id) { remove(id, i) {
var url = myJs.url.app.RemoveApp; var url = myJs.url.app.RemoveApp;
myJs.post(url, { id: id }, function (d) { myJs.post(url, { id: id }, function (d) {
var nArr = []; mydata.app_index.rows.splice(i, 1);
$.each(mydata.app_index.rows, function () {
if (this.Id != id) {
nArr.push(this);
}
});
mydata.app_index.rows = nArr;
}, function (s, i, m) {
myJs.msg(m);
}); });
}, },
}, },

View File

@ -18,12 +18,12 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="u in users"> <tr v-for="(u,index) in users">
<td>{{u.Id}}</td> <td>{{u.Id}}</td>
<td>{{u.UserName}}</td> <td>{{u.UserName}}</td>
<td>{{u.Name}}</td> <td>{{u.Name}}</td>
<td>{{u.Status}}</td> <td>{{u.Status}}</td>
<td><input type="button" value="删除" v-on:click="removeUser(u.Id)" /></td> <td><input type="button" value="删除" v-on:click="removeUser(u.Id,index)" /></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -65,15 +65,9 @@
userIndex.tableShow = true; userIndex.tableShow = true;
}); });
}, },
removeUser(id) { removeUser(id, index) {
myJs.post(myJs.url.user.RemoveUser, { adminTicket: this.ticket, id: id }, function (d) { myJs.post(myJs.url.user.RemoveUser, { adminTicket: this.ticket, id: id }, function (d) {
var nArr = []; userIndex.users.splice(index, 1);
$.each(userIndex.users, function () {
if (this.Id != id) {
nArr.push(this);
}
});
userIndex.users = nArr;
}); });
}, },
} }