流星角集合查找方法不起作用

时间:2015-05-15 04:18:22

标签: angularjs mongodb meteor

我正在尝试优化角度/流星代码。我有一个集合

Customers = new Mongo.Collection("Customers");

我展示它们的方式是:

ng-repeat="customer in customerController.customers | filter: {customerStore: myStore} ">

和我的CustomerController

this.customers = $meteor.collection(customers);

这种方法(虽然有效)现在开始在客户端的服务器上占用大量内存,因为它们正在添加越来越多的商店。

所以我尝试在向客户端发送信息之前过滤服务器端。

新代码:

集合代码是相同的

Customers = new Mongo.Collection("Customers");

ng-repeat代码不同

ng-repeat="customer in customerController.getCustomers(myStore) ">

我的控制器现在有这个方法:

    this.getCustomers = function(findByStore){
        return Customers.find({customerStore.$ : findByStore});
    }

这个问题在于它每次都会返回一个新的集合,因此angular将其视为一个不同的对象,并尝试重新呈现该页面。

https://docs.angularjs.org/error/ $ rootScope / infdig P0 = 10安培; P1 =%5B%5B%7B%22msg%22:%22fn:%20regularInterceptedExpression%22%22newVal%22:21,%22oldVal%22: 19%7D%5D,%5B%7B%22msg%22:%22fn:%20regularInterceptedExpression%22%22newVal%22:23,%22oldVal%22:21%7D%5D,%5B%7B%22msg%22: %22fn:%20regularInterceptedExpression%22%22newVal%22:25,%22oldVal%22:23%7D%5D,%5B%7B%22msg%22:%22fn:%20regularInterceptedExpression%22%22newVal%22:27, %22oldVal%22:25%7D%5D,%5B%7B%22msg%22:%22fn:%20regularInterceptedExpression%22%22newVal%22:29,%22oldVal%22:27%7D%5D%5D

One common mistake is binding to a function which generates a new array every time it is called.

有人建议我试试

return $meteor.collection(Customers.find({'customerStore.$' : findByStore}));

然后我收到错误

TypeError: The first argument of $meteorCollection must be a function or a have a find function property.

0 个答案:

没有答案