Angularjs筛选器将数据从一个表传递到另一个表(使用复选框)
我试图用另一个表提供的数据填充一个表。Angularjs筛选器将数据从一个表传递到另一个表(使用复选框),angularjs,Angularjs,我试图用另一个表提供的数据填充一个表。 表一列出了所有数据,每个项目都有一个复选框。 表2应仅包含表1中已勾选的项目 我可以看到“Checked”值被设置为true,但不起作用(我在表2中始终获得所有数据)。 $scope.data 对象{key:“3”,value:“c”,$$hashKey:“006”,选中:true} 预期结果: <span>Table One</span> <div ng-controller="checkBoxCtrl"> <
表一列出了所有数据,每个项目都有一个复选框。
表2应仅包含表1中已勾选的项目 我可以看到“Checked”值被设置为true,但不起作用(我在表2中始终获得所有数据)。
$scope.data
对象{key:“3”,value:“c”,$$hashKey:“006”,选中:true} 预期结果:
<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'}
];
};
表一
{{data.key}
{{data.value}}
表二
{{data.key}
{{data.value}}
var-app=angular.module('myApp',[]);
函数checkBoxCtrl($scope){
$scope.tableOne=[
{键:'1',值:'a'},
{键:'2',值:'b'},
{键:'3',值:'c'},
{键:'4',值:'d'}
];
};
以下是过滤属性的语法……基本上它是一个对象,但我想从角度来看,它可能被视为一个表达式。我不是100%确定如何用文字来定义它…但它是有效的
<tr ng-repeat="data in tableOne | filter: {checked:true}">
只需删除其中一个等号即可
<tr ng-repeat="data in tableOne | filter: checked=true">
如果您的过滤器是filter:data,会发生什么情况。CheckedTanks,我“非常接近”。