【发布时间】:2017-12-02 20:39:28
【问题描述】:
我在我的项目中使用 Meteor 和 blaze,我想在 Meteor 模板中调用 JavaScript 函数。更准确地说,我当然使用了发布者订阅者,但是当我订阅以从 mongo DB 中检索信息时,我希望触发一个函数。
事实上,我检索数据,但它处理“真”或“假”之类的行数据,我想根据数据结果调用一个影响不同属性的函数。
例如,如果我的 db 的元素设置为“true”,当订阅准备就绪时(或在我的页面加载后),它将用绿色矩形替换“true”。
为此,我想知道我们是否可以使用
Template.devicesConfiguration.onCreated(function(){
var self = this;
self.autorun(function(){
self.subscribe('Buttons');
//call a javascript function that uses the result of the db
});
});
或在
Template.devicesConfiguration.helpers({
buttons:()=>{
//call a javascript function that uses the result of the db
return ButtonsCollection.find({});
}
});
甚至是一种方法?
有人有想法吗?多谢 !
【问题讨论】:
标签: javascript templates meteor meteor-blaze