在初始加载时,所有作业在无序列表中按预期加载。我有一个下拉菜单,用户可以通过从此菜单中选择一个选项来限制作业。我遇到的问题是,当集合从服务器获取结果时,页面上的计数器会倒计时"或" up"因为返回了集合结果,并且无序列表中的作业列表似乎"循环"。
任何方法都可以在没有倒计时的情况下加载结果?
客户端:
Meteor.subscribe('cities');
Meteor.autorun(function(){
Meteor.subscribe('jobs', Session.get('currentIndustryOnet'), Session.get('currentMapArea'));
});
Meteor.startup(function(){
Meteor.call('getJobsCount', function(err, count){
Session.set('jobCount', count);
});
});
Template.header.jobCount = function() {
return Session.get('jobCount');
}
Template.list.jobs = function() {
if(!Session.get('page'))
plotCities();
Session.set('jobCount', Jobs.find().count());
return Pagination.collection(Jobs.find({}).fetch());
}
var plotCities = function() {
var jobs = Jobs.find().fetch();
var addresses = _.chain(jobs)
.countBy('address')
.pairs()
.sortBy(function(j) {return -j[1];})
.map(function(j) {return j[0];})
.first(100)
.value();
gmaps.clearMap();
$.each(_.uniq(addresses), function(k, v){
var addr = v.split(', ');
Meteor.call('getCity', addr[0].toUpperCase(), addr[1], function(error, city){
if(city) {
var opts = {};
opts.lng = city.loc[1];
opts.lat = city.loc[0];
opts.population = city.pop;
opts._id = city._id;
gmaps.addMarker(opts);
}
});
})
}
服务器:
Meteor.publish('jobs', function(onet_code, city_id){
var cursor, options = {};
if(city_id) {
var city = Cities.findOne(city_id);
options.address = city.city.capitalize() + ", " + city.state;
}
if(onet_code) {
options.onet = onet_code;
}
if(onet_code || city_id){
cursor = Jobs.find(options, { sort: {dateacquired: -1} });
} else {
cursor = Jobs.find({}, {sort: {dateacquired: -1}});
}
return cursor;
});
Meteor.publish('cities', function(){
return Cities.find({}, {sort: {pop: -1}, limit: 100});
});