我正在使用流星厨师基地,而且我在使用react-komposer时遇到了反应问题。我有一个订阅调用,它从url(lectureId,courseId)获取id,首先查找(并创建,如果需要)带有这些id的userLecture文档和它用于获取当前Question订阅的currentQuestion字段。我稍后更新了currentQuestion id但问题订阅在硬页面刷新之前不会更新。当输入实际没有变化时,如何才能使该订阅被动?
const composer = (params, onData) => {
let subscription = Meteor.subscribe('questionFromSlugs', params.courseSlug, params.lectureSlug);
if (subscription.ready()) {
const question = Questions.findOne();
const userLecture = UserLecture.findOne();
onData(null, { question });
}
};
export default composeWithTracker(composer, Loading)(QuizQuestion);
这是流星订阅:
Meteor.publish('questionFromSlugs', function(courseSlug, lectureSlug){
check(courseSlug, String);
check(lectureSlug, String);
check(this.userId, String);
let user = this.userId;
let lecture = Lectures.findOne({courseSlug: courseSlug, slug: lectureSlug});
let course = Courses.findOne({slug: courseSlug});
if (lecture != null && course != null) {
var thisLectureScore = UserLecture.find({
userId: user,
lectureId: lecture._id
}).count();
if (thisLectureScore == 0){
UserLecture.insert({
userId: user,
courseId: course._id,
lectureId: lecture._id,
lectureScore: 0,
currentLevel: 1
});
}
let userLecture = UserLecture.findOne({
userId: user,
courseId: course._id,
lectureId: lecture._id
});
if (userLecture != null){
return [
Questions.find({_id: userLecture.currentQuestionId}),
UserLecture.find({
userId: user,
courseId: course._id,
lectureId: lecture._id
})
]
}
}
});
答案 0 :(得分:0)