mongodb - Meteor:从 mongodb 渲染内容后应用函数

标签 mongodb meteor sage

我正在使用 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/

相关文章:

Python (1..n) 语法?

node.js - 将键添加到带条件的嵌套数组

mongodb - meteor react : in constructor collection is empty

python - RDSA 在 sage 上的实现

meteor - url方案meteor ://💻app/. ....在meteorjs中

docker - Mup安装失败,显示 “endpoint with name mongodb already exists in network bridge”

python - 计算求解 100 个变量的非线性方程组

c# - 在 MongoDB C# 驱动程序 2.2 中使用 AsQueryable 进行投影

node.js - 使用 Redis 和 MongoDB (HyperLogLog) 计算唯一值

javascript - 路径在 Meteor JS 中没有方法 'parse'