我有以下几点:
Meteor.startup(function() {
var computation = Tracker.autorun(function() {
var currentChapter;
currentChapter = Chapters.findOne({
_id: currentChapterId
});
if (currentChapter) {
if (currentChapter.title) {
$("#input-title").val(currentChapter.title);
} else {
$("#input-title").val("");
}
if (currentChapter.content) {
$("#input-content").html(currentChapter.content);
} else {
$("#input-content").html("");
}
}
return computation.stop();
});
});现在我明白了:
跟踪器afterFlush函数的异常:无法调用未定义的TypeError的方法“停止”:无法调用未定义的方法“停止”
我想要做的是,一旦currentChapter为真,就停止计算。我做错了什么?
发布于 2014-10-12 10:24:23
有两件事:
1-您的自动运行函数获得传递给它的计算句柄,因此您可以像这样停止它:
Meteor.startup(function() {
var computation = Tracker.autorun(function(thisComp) {
var currentChapter;
currentChapter = Chapters.findOne({
_id: currentChapterId
});
if (currentChapter) {
if (currentChapter.title) {
$("#input-title").val(currentChapter.title);
} else {
$("#input-title").val("");
}
if (currentChapter.content) {
$("#input-content").html(currentChapter.content);
} else {
$("#input-content").html("");
}
thisComp.stop();
}
});
});2-在您的代码中,计算将在第一次运行结束时停止,不管如何-您应该在if (currentChapter)块中停止它。
https://stackoverflow.com/questions/26323633
复制相似问题