English 中文(简体)
角 JS - 在对象被摧毁后删除表格行
原标题:AngularJS - Remove table row after object destroyed

我有一个角JS 应用程序, 返回 Json 对象列表, 然后通过这些对象进行循环, 并将其放入表格 。

表格中每个项目都有一个“删除”按钮,使用 ng-kick 方法:

<td><a ng-click="testButton()" class="btn btn-danger btn-mini">Delete</a></td>

我正使用 ng -resources 来删除对象 - 这很好。

但是,我也希望能够隐藏(或删除)包含对象的行和删除后的删除按钮 -- -- 最好使用 " 强 " JQuery

这是我的毁灭方法:

$scope.destroyThing = function() {
        $scope.thing= this.thing;
        $scope.thing.$destroy();
        $(this.thing).closest("tr").hide(); // something like this maybe
    }

该方法将物体摧毁得非常顺利 - 它只是不删除行... 所以我尝试了记录物体返回 当我点击按钮时返回:

$scope.testButton = function() {
        console.log(this);
    }

这似乎返回了角范围天体本身,但我无法找到途径访问它所涉及的任何DOM元素。

这里有一个屏幕截图, 显示您从测试按钮函数返回的对象 - 点击此按钮可以触发 :

""https://i.sstatic.net/HjR6I.png" alt="此处输入图像描述"/ >

< 加强> 如何用 JQuery 访问与角天体有关的 DOM 元素?

EDIT

这是完整的表格行 :

<tr ng-repeat="franchise in franchises">
                <td ng-model="franchiseName">{{franchise.franchise_name}}</td>
                <td ng-model="franchiseNumber">{{franchise.franchise_number}}</td>
                <td><a class="btn btn-mini">Edit</a></td>
                <td><a ng-click="destroyFranchise()" class="btn btn-danger btn-mini">Delete</a></td>

            </tr>
最佳回答

您不想从控制器中访问 DOM 。 这是对角的 Zen: - D

使用 ng-hide 指令 :

<td><a ng-click="hide()" ng-hide="isHidden">Delete</a></td>

控制器只需更改模式值, 即 < code> ng- hide 受约束( 在此情况下, < code> is Hidden 属性) 。

您如何填充表格? 您是否使用 < code> ng- repeat ? 如果是, 足够从收藏中删除项目 < code > ng- repeat 重复并自动更新 DOM 。

查看

问题回答

直接与 DOM 玩弄 DOM 并不是角法, 对于来自 Google 但仍需要这样做的人来说,

  1. Use Angular-UI s jQuery Passthrough (recommended)
  2. Write an Angular directive and wrap the DOM handling in there. A starting point: jsfiddle.

使您的桌面滚动方法以行为参数 。

<tbody id= "table_row">
 <tr ng-repeat="row in rows" ng-click="tableRowClicked(row)">
    <td ng-repeat="col in row">{{col}}</td>
</tr>




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签