如何通过双击显示表tr`` |角js

时间:2018-04-08 05:21:51

标签: html angularjs angular-ng-if

状态: 我有一个视图,用户双击某一行来编辑表数据。

查看

<table>
<!-- give the modal value on doble click to be used as condition in the ng-show -->
  <tbody  ng-model="facture_details">
       <tr ng-if="facture_details == 'editMode'" ng-repeat="user in selectedFacture">
          <td>
            <input type="checkbox" ng-model="user.selected" />
          </td>
          <td data-title="Name">{{ user.name }}</td>
          <td data-title="Last Name" data-field="lastName">{{ user.lastName }}</td>
          <td><a class="btn btn-default" ng-click="edit(user)"><i class="icon-pencil"></i>Edit</a>
          </td>
            <div>
            <tr>
              <td>{{ user.name }} {{ user.lastName }}</td>
              <td>{{ user.name }} {{ user.lastName }}</td>
            </tr>
          </div>
      </tr>
  </tbody>
</table>

所以在双击时我想显示tr,我尝试过ng-show但是它也没有用。 提前致谢

1 个答案:

答案 0 :(得分:1)

使用ng-if如果您还需要检查类型,则需要使用 ===

 <div ng-if="facture_details === 'editMode'" >

也将ng-dblclick设置为,

  <tr ng-repeat="sf in selectedFacture" ng-dblclick="facture_details='editMode'">

<强>样本

var app = angular.module('testApp',[])
app.controller('testCtrl',function($scope){
  $scope.selectedFacture = [{
      name: "Joe",
      lastName: "Carter"
    }, {
      name: "Bob",
      lastName: "Barker"
    }, {
      name: "Peter",
      lastName: "Griffin"
    }, {
      name: "Don",
      lastName: "Cherry"
    }, {
      name: "Bobby",
      lastName: "Fillet"
    }, {
      name: "Joey",
      lastName: "Diaz"
    }, {
      name: "Zoe",
      lastName: "Dejavous"
    }, {
      name: "Tom",
      lastName: "Jones"
    }];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
<tbody>
  <table ez-table="users" data-count="4">
  <button ng-dblclick="facture_details='editMode'">click</button>
       <tr ng-if="facture_details == 'editMode'" ng-repeat="user in selectedFacture">
        <td>
          <input type="checkbox" ng-model="user.selected" />
        </td>
        <td data-title="Name">{{ user.name }}</td>
        <td data-title="Last Name" data-field="lastName">{{ user.lastName }}</td>
        <td><a class="btn btn-default" ng-click="edit(user)"><i class="icon-pencil"></i>Edit</a>
        </td>
      </tr>
    </table> 
 
</tbody>
</body>