假设我们需要在视图上显示过滤的任务,第一步我们得到了所有购买发布/订阅的任务列表:
发布:
Meteor.publish("tasks", function(options){
return Tasks.find(options);
});订阅:
var allTasks = $meteor.collection(Tasks).subscribe('tasks', {});现在,假设我只需要在$scope中看到'active‘变量设置为true的任务。
如下所示:
$scope.active_tasks = getFilteredTasks(allTasks, {active: true}) 如何替换getFilteredTasks(allTasks,{active: true})来获取只有active==true变量的任务?
我知道我们可以在订阅任务时设置“选项”,比如:
{active: true}但这无助于解决这个问题。目标是只订阅一次,然后使用筛选器仅显示部分任务。
我仍然没有完成Angular-Meteor tutorial,所以它可能会在稍后解释,如果你能给我指出正确的教程,它将大大加快我的学习速度。
提前谢谢。
发布于 2015-05-30 23:17:05
好的。看起来解决方案是在角度边。所以在控制器中我们得到了所有的任务:
$scope.active_tasks = $meteor.collection(Tasks);在视图方面,我们对它们进行过滤:
<input ng-model="freeText">
<tr ng-repeat="task in active_tasks | filter:freeText ">
<td>{{ task }}</td>
</tr>:)
发布于 2015-06-06 20:10:45
@pumych解决方案是有效的解决方案。您还可以使用
$scope.$meteorSubscribe ('tasks');
$scope.activeTasks = $meteor.collection (function (){
// active tasks will only be the filtered result
return Tasks.find (active: true) ;
}); 在这里https://medium.com/@tally_b/coll-pub-sub-with-angular-meteor-cb13fe48f5701阅读有关Angular Meteor数据流的信息。有关更多详细信息,请查看示例和github代码。
https://stackoverflow.com/questions/30546029
复制相似问题