【发布时间】:2015-09-27 05:28:34
【问题描述】:
所以我有下面的代码。第一个从会话中读取过滤器数据并返回汽车列表。该结果的第二个总汽车数量。显然,代码几乎是重复的。我可以合并它们并返回汽车对象和汽车数量吗?或者至少我可以从 total_car 函数内部调用 car 函数?
Template.list.helpers({
car: function() {
var filter_str = {}
if (Session.get('manufactured_year_min')) {
filter_str.manufactured_year = {$gt: parseInt(Session.get('manufactured_year_min'))};
}
return Car.find(filter_str);
},
total_car: function() {
var filter_str = {}
if (Session.get('manufactured_year_min')) {
filter_str.manufactured_year = {$gt: parseInt(Session.get('manufactured_year_min'))};
}
return Car.find(filter_str).count();
}
});
【问题讨论】: