【发布时间】:2014-06-03 08:06:17
【问题描述】:
假设我有这些模型
第一目标
{
GoalId: 30
GoalDesc: "The quick brown fox"
},
{
GoalId: 31
GoalDesc: "The quick brown fox junior"
},{
GoalId: 32
GoalDesc: "The quick brown fox senior"
}
第二个目标
{
GoalId: 30
GoalDesc: "The quick brown fox"
},
{
GoalId: 35
GoalDesc: "The big bad fox"
},{
GoalId: 36
GoalDesc: "The little red fox"
}
这些是我的 html:
<table>
<tr ng-repeat="goal in firstGoals" id="choose-goals-row-{{goal.GoalId}}">
<td><input type="checkbox" id="selection-chkbox-{{goal.GoalId}}" ng-model="secondaryGoals[$index].selected" ng-true-value="true" ng-false-value="false" style="float:left;margin-left:0px;"/></td>
<td>{{goal.GoalDesc}}</td>
</tr>
</table>
<table>
<tr ng-repeat="goal in secondGoals" id="choose-goals-row-{{goal.GoalId}}">
<td><input type="checkbox" id="selection-chkbox-{{goal.GoalId}}" ng-model="secondaryGoals[$index].selected" ng-true-value="true" ng-false-value="false" style="float:left;margin-left:0px;"/></td>
<td>{{goal.GoalDesc}}</td>
</tr>
</table>
如何使用过滤比较这两个模型?我需要通过其 GoalId 属性使用 jQuery 和 AngularJS 在第二个模型“secondGoals”中不存在的第一个模型“firstGoals”对象?
firstGoals 应该是实时的或可观察的(我正在使用最新的 AngularJS 库) 我现在正在做的是,如果我点击删除按钮,我在 firstGoals 模型中选择的目标将被转移(推送和拼接方法)到 secondGoals反之亦然,删除它是批量添加/删除对象/数组。
附加:应该在 firstGoals 显示的所有内容都应该在 secondGoals 不存在,因为我们正在以相同格式拼接和推送批量对象。我是firstGoals 模型的思考应该是自动刷新
【问题讨论】:
-
也许只是尝试创建一个自定义过滤器? docs.angularjs.org/guide/filter
-
这就是我需要的。不过我不知道。:(