Javascript 如何使用基于文本框的angularjs编辑行?

Javascript 如何使用基于文本框的angularjs编辑行?,javascript,angularjs,Javascript,Angularjs,这是我表格的一部分: <tr ng-repeat="f in fields" track by $index" class="clickable" > <td><input type="checkbox" ng-model="selectedEntities[$index].id" ng-true-value="{{f.id}}"/></td> <td>{{f.id}}</td>

这是我表格的一部分:

<tr ng-repeat="f in fields"  track by $index" class="clickable" >

       <td><input type="checkbox" ng-model="selectedEntities[$index].id" ng-true-value="{{f.id}}"/></td> 
      <td>{{f.id}}</td>
      <td>{{f.fieldName}}</td>
      <td>{{f.fieldType.typeName}}</td>
       <td>{{f.relation.entityName}}</td>
      <td>{{f.inputType}}</td>
      <td>{{f.size}}</td>
      <td>{{f.primary}}</td>
      <td>{{f.index}}</td>

      <td><button ng-click="deleteField($index)">delete</button></td> 
       <td><button ng-click="UpdateField($index)">Update</button></td> 

</tr>

我应该在控制器中执行什么操作

我不确定我是否理解您想要做什么,但下面是检索所有选定行的方法:

看法


字段上会有一个编辑模式标志。这将由复选框设置:

<td><input type="checkbox" ng-model="f.editMode"/></td>

你想让复选框做什么?选择我应该更新的行,但删除和更新按钮在该行上,那么你为什么需要选择它?是的,你是对的,我会在没有复选框的情况下尝试。我的问题不是复选框,但我不知道如何编辑行控制器。现在可以编辑,但要保存编辑,我使用用于保存字段但不起作用的函数$scope.saveEdits=function{$scope.field.entity=$scope.currentEntity;$http.post/saveField,$scope.field.successfunctiondata{$scope.fields.pushdata;console.log$scope.entities;};要获取当前字段,您应该使用$scope.fields[index],我认为这里的按钮更新没有任何重要性,因为当我选中复选框时,我有文本框要编辑,而不必单击按钮编辑??另一个问题是,我有deleteButton,当我在按钮复选框中添加f.editmode时,delete不起作用。复选框用于将其置于编辑模式,更新按钮用于保存数据。看看我的PlunkrYes中的delete,我刚刚看到了它,我现在明白了,但是对于控制器中的saveEdits,我使用$scope.saveEdits=函数{$scope.editmode=false;$scope.field=angular.copy$scope.currentrow;它错了吗?};
app.controller('Ctrl'[function(){

  $scope.getAllSelected = function() {
     var result =[];
     angular.forEach($scope.items, function(item) {
         if (item.selected) {
             result.push(item);
             return;
         }
     });
     return result;
  }
}]);
<td><input type="checkbox" ng-model="f.editMode"/></td>
<td>
  <span ng-show="!f.editMode">{{f.fieldName}}</span>
  <input type="text" ng-model="f.fieldName" ng-show="f.editMode"/>
</td>
<td><button ng-click="updateField($index)" ng-show="f.editMode">Update</button></td> 
$scope.deleteField = function (index) {
  var field = $scope.fields[index];
  var url = '/fields/' + field.id;

  $http.delete(url).then(function () {
    $scope.fields.splice(index, 1);
  });
};

$scope.updateField = function (index) {
  var field = $scope.fields[index];
  var url = '/fields/' + field.id;

  $http.put(url, field).then(function () {
    field.editMode = false;
  });
};