问题描述:

I'm setting up simple pub/sub on a mongo collection in a meteor application.

// On Server

Meteor.publish('records', function (params) {

if (params.gender === "Male") {

params.gender = "M";

} else if (params.gender === "Female") {

params.gender = "F";

}

return Records.find({

gender: params.gender || {$exists: true},

age: {

$lte: params.ageRange.max,

$gte: params.ageRange.min

}

});

});

//On Client

this.computationBlock = Tracker.autorun( () => {

Meteor.subscribe("records",

_.pick(this, ["gender","ageRange"]));

RecordActions.recordsChange(Records.find({}).fetch());

});

相关阅读:
Top