Angular X-Editable 使 editable 字段出现在下一个 table 单元格中
Angular X-Editable makes editable field appear in next table cell
我目前正在尝试在我的 Angular 项目中实施 X-Editable。我有一个 table,可以添加和删除条目,我也希望能够编辑它们。我有以下内容:
HTML:
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Nr.</th>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="users in $ctrl.users"> //user should be editable
<td>
{{$index + 1}}
</td>
<td editable-text="users">
{{users}}
</td>
<td>
<div class="btn-group">
<span ng-click="$ctrl.removeUser($index)" class="glyphicon glyphicon-trash"></span>
</div>
</td>
</tr>
</tbody>
</table>
<input ng-model="$ctrl.addMe"/>
<button ng-click="$ctrl.addUser()">Add</button>
<p id="errormessage">{{$ctrl.errortext}}</p>
JS:
class UserlistController{
constructor(){
this.users=["John","Peter","Julia"];
this.errortext="";
}
addUser(){
this.errortext="";
if(this.users.indexOf(this.addMe)==-1){
this.users.push(this.addMe);
}else{
this.errortext="The user does already exist!";
}
}
removeUser(user){
this.users.splice(user,1);
this.errortext = "";
}
}
export default UserlistController;
甚至可以编辑单元格,所以点击单元格,输入另一个值,然后点击保存就可以完成它的工作,但是有一个问题:出现的输入字段出现在下一个 table 单元格,所以它完全弄乱了 table。有没有人碰巧知道,为什么会发生这种情况以及如何解决?你可以看到它的样子here。所以 x-editable 单元格进入 "Action" 列,垃圾从 table 中移出。有什么想法吗?
我目前正在尝试在我的 Angular 项目中实施 X-Editable。我有一个 table,可以添加和删除条目,我也希望能够编辑它们。我有以下内容:
HTML:
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Nr.</th>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="users in $ctrl.users"> //user should be editable
<td>
{{$index + 1}}
</td>
<td editable-text="users">
{{users}}
</td>
<td>
<div class="btn-group">
<span ng-click="$ctrl.removeUser($index)" class="glyphicon glyphicon-trash"></span>
</div>
</td>
</tr>
</tbody>
</table>
<input ng-model="$ctrl.addMe"/>
<button ng-click="$ctrl.addUser()">Add</button>
<p id="errormessage">{{$ctrl.errortext}}</p>
JS:
class UserlistController{
constructor(){
this.users=["John","Peter","Julia"];
this.errortext="";
}
addUser(){
this.errortext="";
if(this.users.indexOf(this.addMe)==-1){
this.users.push(this.addMe);
}else{
this.errortext="The user does already exist!";
}
}
removeUser(user){
this.users.splice(user,1);
this.errortext = "";
}
}
export default UserlistController;
甚至可以编辑单元格,所以点击单元格,输入另一个值,然后点击保存就可以完成它的工作,但是有一个问题:出现的输入字段出现在下一个 table 单元格,所以它完全弄乱了 table。有没有人碰巧知道,为什么会发生这种情况以及如何解决?你可以看到它的样子here。所以 x-editable 单元格进入 "Action" 列,垃圾从 table 中移出。有什么想法吗?