gpt4 book ai didi

javascript - 从 div angularjs 中删除生成的元素

转载 作者:行者123 更新时间:2023-11-27 23:42:37 26 4
gpt4 key购买 nike

我想在单击删除按钮时删除条件列表项。现在只有过滤器正在刷新。这些表没有被删除。解决这个问题的建议。

  • HTML

       <ul class="list-unstyled">
    <li style="display: inline-block" ng-repeat="crtia in newCriteria" >
    <table>
    <tr>

    <td>
    <select class="input-sm" ng-model="crtia.name" ng-options="searchopt for searchopt in searchcriteria " ng-click="searchy.check()"></select>
    </td>
    <td>
    <input class="input-sm " ng-model="crtia.value" placeholder="{{crtia.name}}" ng-change="newList()" ng-click="searchy.check()" />
    </td>
    <td>
    <button type="button" class="btn btn-danger btn-xs" aria-label="Left Align" ng-click="removeCriteria($index)">
    <span class="glyphicon glyphicon-remove" aria-hidden="true" ></span>
    </button>
    </td>
    </tr>

    </table>
    </li>
    </ul>
  • JS

         $scope.removeCriteria=function($index){
    $scope.searchy.check();
    alert($index);
    $scope.newCriteria.splice($index,1);
    $scope.newList(); //Refreshes the filter
    }

最佳答案

试试这个

HTML

<button type="button" class="btn btn-danger btn-xs" aria-label="Left Align" data-ng-click="removeCriteria(crtia)">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>

JS:

$scope.removeCriteria = function (sourceToRemove) {
$scope.searchy.check();

var index = $scope.newCriteria.indexOf(sourceToRemove);
$scope.newCriteria.splice(index, 1);
$scope.newList(); //Refreshes the filter
}

更新Plunker

关于javascript - 从 div angularjs 中删除生成的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33536789/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com