我正在使用 sage cell 将 html 转换为数学内容
Template.home.rendered = function(){
\\ apply sagecell and mathjax
}
但是,渲染的内容来自 mongo,因此有时会在应用 sage cell 后加载。我可以做这样的事情
Template.home.rendered = function(){
Deps.autorun(function(){
if (Content.findOne({_id: ...})){
\\ apply sagecell and mathjax
}
});
}
这更好了,但仍然不能一直工作。我可以使用其他东西来检测内容是否完全呈现?
最佳答案
已编辑新回复:
<template name='pendingAnswer'>
The answer to your question, coming back whenever, is:
{{>answer}}
</template>
<template name='answer'>
{{fromSage}}
</template>
Template.answer.helpers({
fromSage: function () {
Session.get('fromSage');
}
});
Invoked whenever - from a button, from navigating to the page, on blur...
function GetAnswerFromSage(data) {
callHTTP(website,data, callbackFromSage)
}
function callbackFromSage(err, data) {
if (err) then log(err);
Session.set('fromSage', data);
}
之前:尝试在检索 mongo 时进行转换: From Meteor Doc
// An Animal class that takes a document in its constructor
Animal = function (doc) {
_.extend(this, doc);
};
_.extend(Animal.prototype, {
makeNoise: function () {
console.log(this.sound);
}
});
// Define a Collection that uses Animal as its document
Animals = new Meteor.Collection("Animals", {
transform: function (doc) { return new Animal(doc); }
});
// Create an Animal and call its makeNoise method
Animals.insert({name: "raptor", sound: "roar"});
Animals.findOne({name: "raptor"}).makeNoise(); // prints "roar"
关于mongodb - Meteor:从 mongodb 渲染内容后应用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18517050/