如何正确删除所选项目ui.grid角JS [英] How to properly delete selected items ui.grid Angular JS

查看:550
本文介绍了如何正确删除所选项目ui.grid角JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些困难,了解可通过UI格的属性/功能。我常常感到困惑与previous版本NG-网格。我试图找到删除检查入境的最佳方式是什么。这里是我的标记,但由于不是很理解,如果我有一个索引,或通过一排的实体数可供选择:

I am having some difficulties understanding the properties/functions available through ui-grid. I often get confused with its previous version ng-grid. I am trying to find what the best way of deleting a checked-entry would be. Here is my markup, but due to not quite understanding if I have an index, or count available through a row entity:

HTML

       <div class="form-group">
          <button type="button" id="addData" class="btn btn-success" ng-click="addData()">Add Data</button>
          <button type="button" id="removeData" class="btn btn-success" ng-click="removeData()">Remove First Row</button>
          <br>
          <br>
          <div id="grid1" ui-grid="gridOptions" ui-grid-edit ui-grid-selection external-scopes="myViewModel" class="grid"></div>
    </div>

这在于我的控制器下的:

which lies under my controller:

 $scope.removeData = function () {
        console.log($scope.gridApi.selection.getSelectedRows());

        var items = $scope.gridApi.selection.getSelectedRows();

        angular.forEach($scope.myData, function (data, index) {
            angular.forEach(items, function (item) {
                if (item.displayValue = data.displayValue)
                {
                    $scope.myData.splice(index, 1);
                }

            });

其中, displayValue 是我的专栏的属性和 $ scope.myData 是我的数据。是否有不同的方式,以该选择发送到控制器去除?目前的办法,我有它不工作(明显)。任何帮助将AP preciated。如果我的标记是不完整的,我会在必要时更新。谢谢!

where displayValue is a property of my column and $scope.myData is my data. Is there a different way to send that selection to the controller for removal? The current way I have it does NOT work (obviously). Any help will be appreciated. If my markup is incomplete, I'll update it as necessary. Thank you!

推荐答案

您的解决方案看起来有点复杂。这里是我的删除功能:

Your solution looks a little complicated. Here is my delete function:

$scope.deleteSelected = function(){
  angular.forEach($scope.gridApi.selection.getSelectedRows(), function (data, index) {
    $scope.gridOptions.data.splice($scope.gridOptions.data.lastIndexOf(data), 1);
  });
}

下面是一个 plunker 基础上,210_selection教程。

Here is a plunker based on the 210_selection tutorial.

这篇关于如何正确删除所选项目ui.grid角JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆