Angularjs Filter将数据从一个表传递到另一个表(使用复选框)

时间:2013-12-11 01:21:28

标签: angularjs

我正在尝试使用另一个表提供的数据来填充表格 表一包含每个项目的复选框的所有数据 表2应仅包含表1中已检查过的项目。

我可以看到' Checked' value gets设置为true,但不起作用(我在表2中始终获得所有数据) $ scope.data
对象{key:" 3",value:" c",$$ hashKey:" 006",checked:true}

JSFiddle

期望的结果:

Desired Result

<span>Table One</span>
<div ng-controller="checkBoxCtrl">
<table width="400" border="1">
    <tr ng-repeat="data in tableOne" id="item{{data.key}}">
        <td width="20px">
            <input type="checkbox" ng-model="data.checked">
        </td>
        <td>{{data.key}}</td>
        <td>{{data.value}}</td>
    </tr>
</table>

<br>
<span>Table Two</span>
<table width="400" border="1">
        <tr ng-repeat="data in tableOne | filter: data.checked==true">
            <td>{{data.key}}</td>
            <td>{{data.value}}</td>
        </tr>

</table>


var app = angular.module('myApp', []);

    function checkBoxCtrl($scope){
        $scope.tableOne=[
                        {key: '1',  value: 'a'},
                        {key: '2',  value: 'b'},
                        {key: '3',  value: 'c'},
                        {key: '4',  value: 'd'}
                        ];  
        };

2 个答案:

答案 0 :(得分:1)

只需删除其中一个等号。

<tr ng-repeat="data in tableOne | filter: checked=true">

答案 1 :(得分:0)

这是过滤属性的语法....基本上它是一个对象,但我想在角度方面它可能被认为是一个表达式。我不是100%肯定如何用文字来定义它......但是它有效

<tr ng-repeat="data in tableOne | filter: {checked:true}">

DEMO