Javascript 角度X可编辑只有一行应该编辑,如果我点击下一行编辑,上一行应该重置为初始状态

Javascript 角度X可编辑只有一行应该编辑,如果我点击下一行编辑,上一行应该重置为初始状态,javascript,angularjs,Javascript,Angularjs,角度X可编辑只有一行应该编辑,如果我点击下一行编辑,上一行应该重置为初始状态 以下是我的HTML代码: <h4>Angular-xeditable Editable row (Bootstrap 3)</h4> <div ng-app="app" ng-controller="Ctrl"> <table class="table table-bordered table-hover table-condensed"> <tr s

角度X可编辑只有一行应该编辑,如果我点击下一行编辑,上一行应该重置为初始状态

以下是我的HTML代码:

<h4>Angular-xeditable Editable row (Bootstrap 3)</h4>
<div ng-app="app" ng-controller="Ctrl">
   <table class="table table-bordered table-hover table-condensed">
    <tr style="font-weight: bold">
      <td style="width:35%">Name</td>
      <td style="width:20%">Status</td>
      <td style="width:20%">Group</td>
      <td style="width:25%">Edit</td>
    </tr>
    <tr ng-repeat="user in users">
      <td>
        <!-- editable username (text with validation) -->
        <span editable-text="user.name" e-name="name" e-form="rowform" onbeforesave="checkName($data, user.id)" e-required>
          {{ user.name || 'empty' }}
        </span>
      </td>
      <td>
        <!-- editable status (select-local) -->
        <span editable-select="user.status" e-name="status" e-form="rowform" e-ng-options="s.value as s.text for s in statuses">
          {{ showStatus(user) }}
        </span>
      </td>
      <td>
        <!-- editable group (select-remote) -->
        <span editable-select="user.group" e-name="group" onshow="loadGroups()" e-form="rowform" e-ng-options="g.id as g.text for g in groups">
          {{ showGroup(user) }}
        </span>
      </td>
      <td style="white-space: nowrap">
        <!-- form -->
        <form editable-form name="rowform" onbeforesave="saveUser($data, user.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted == user">
          <button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary">
            save
          </button>
          <button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
            cancel
          </button>
        </form>
        <div class="buttons" ng-show="!rowform.$visible">
          <button class="btn btn-primary" ng-click="rowform.$show()">edit</button>
          <button class="btn btn-danger" ng-click="removeUser($index)">del</button>
        </div>  
      </td>
    </tr>
  </table>

  <button class="btn btn-default" ng-click="addUser()">Add row</button>
</div>
以下是我的CSS代码:

div[ng-app] { margin: 10px; }
.table {width: 100% }
form[editable-form] > div {margin: 10px 0;}

在这里,我找到了解决方案,只需修改一些html和ctrl函数

以下是角度可编辑的工作js小提琴链接:-

以下是所做的代码更改:

<form editable-form name="rowform" onbeforesave="saveUser($data, user.id)" ng-show="rowform.$visible" class="form-buttons form-inline checkVisible" shown="inserted == user">
      <button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary">
        save
      </button>
      <button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
        cancel
      </button>
    </form>
    <div class="buttons" ng-show="!rowform.$visible">
      <button class="btn btn-primary" ng-click="editCall(rowform)">edit</button>
      <button class="btn btn-danger" ng-click="removeUser($index)">del</button>
    </div>  

谢谢你-我想使用你已经取得的成果,但是当你在确认后执行rowfrom.$show()时,我将如何$cancel()取消可见的rowform?我尝试了很多方法,但似乎都无法奏效。提前谢谢
<form editable-form name="rowform" onbeforesave="saveUser($data, user.id)" ng-show="rowform.$visible" class="form-buttons form-inline checkVisible" shown="inserted == user">
      <button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary">
        save
      </button>
      <button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
        cancel
      </button>
    </form>
    <div class="buttons" ng-show="!rowform.$visible">
      <button class="btn btn-primary" ng-click="editCall(rowform)">edit</button>
      <button class="btn btn-danger" ng-click="removeUser($index)">del</button>
    </div>  
    $scope.editCall=function(rowform){
     if ( $( ".checkVisible" )
            .is( ":visible" ) ) {
    //alert("One row is active already");
    if(confirm("Are you sure, you want save current row and move to next row")){
    rowform.$show();
    }else{
        alert("Please save current row and move to next");
    }
    }else{
        rowform.$show();

       }
   }