javascript - AngularJS 单击添加/删除复选框和图片

标签 javascript angularjs

我正在寻找一种方法来执行 tr-click。 然后删除其中的所有 img 标签 ( <img src="/img/hake_svart.png" width="30" height="30"> ) 并在 td 中选择该值。

否则,插入图片,然后取消选中该复选框。

想要的结果图像:(意味着检查了两个,一个没有)

enter image description here

功能:

<tr ng-repeat="minion in vm.minions" class="drep_bot_row">

    <td width="40" ng-init="vm.totalprice = vm.totalprice + minion.attack">
        <img src="/img/hake_svart.png" width="30" height="30">
<input type="checkbox" class="ng-hide" ng-model="multiplecheckbox" value="{{ minion.value }} ">
    </td>
</tr>

最佳答案

这纯粹是 Angular 方法,您可以在 vm.minions 的每个对象上都有一个选定的字段,您可以通过单击特定的 tr 来切换该字段。然后可以使用相同的选定标志在适当的条件下显示和隐藏图像/复选框。下面是支持此功能的代码

HTML 为:

 <tr ng-repeat="minion in vm.minions" class="drep_bot_row" ng-click="selectedCurrentMinion(minion)">

<td width="40" ng-init="vm.totalprice = vm.totalprice + minion.attack">
    <img src="/img/hake_svart.png" width="30" height="30" ng-show="minion.selected">
<input type="checkbox" class="ng-hide" ng-model="multiplecheckbox" value="{{  minion.value }} " ng-show="!minion.selected">
</td>
</tr>

然后在 Controller 中你应该写:

angular.forEach($scope.vm.minions,function(eachObj){
  eachObj.selected = false;
});
$scope.selectedArr = [];
$scope.selectedCurrentMinion = function(minion){
  minion.selected = !minion.selected;
  if(minion.selected)
  {
     $scope.selectedArr.push(minion);
  }
  else{
     $scope.selectedArr.splice($scope.selectedArr.indexOf(minion),1);
  }
}

关于javascript - AngularJS 单击添加/删除复选框和图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39275906/

相关文章:

javascript - 如何使用Background.js更新选项卡然后执行内容脚本?

javascript - 日期选择器 Bootstrap 中的工具提示错误

javascript - 有条件地在 AngularJS 中应用 ngClass

javascript - Angular - protected 页面

javascript - p5.j​​s 将不受scale()函数影响的元素添加到 Canvas 上

javascript - CSS3 属性 'backface-visibility' 不适用于任何 IE 版本

javascript - 将三个数组合二为一

javascript - 具有嵌套 Controller 和 "controller as"语法的表单

json - angularjs向json数据添加一列

javascript - 更新云功能中的firestore