Templates 如果数据更改,则更新meteor模板
我有城市流行地名列表的blaze模板:Templates 如果数据更改,则更新meteor模板,templates,meteor,meteor-blaze,Templates,Meteor,Meteor Blaze,我有城市流行地名列表的blaze模板: <template name="city"> {{#each places}} {{this}} {{/each}} </template> 但它不起作用,因为在包含数据的助手数组之前呈现的模板已准备就绪。我应该怎么做才能使helper返回的数据成为被动的,并在模板中显示这些数据?使用onRendered钩子将结果分配给模板实例上的被动变量: import { ReactiveVar } from 'meteor/
<template name="city">
{{#each places}}
{{this}}
{{/each}}
</template>
但它不起作用,因为在包含数据的助手数组之前呈现的模板已准备就绪。我应该怎么做才能使helper返回的数据成为被动的,并在模板中显示这些数据?使用onRendered钩子将结果分配给模板实例上的被动变量:
import { ReactiveVar } from 'meteor/reactive-var';
Template.city.onRendered(function() {
const self = this;
self.places = new ReactiveVar();
service.radarSearch(request, function(points) {
self.places.set(places);
}
});
从这里开始,只需从帮助器返回被动变量:
Template.city.helpers({
places: function() {
const tpl = Template.instance();
const places = tpl && tpl.places.get();
return places || [];
}
});
在这种情况下,您可能甚至不需要等待模板实例被呈现,
onCreated
就足够了。诚然,onCreated
也可以工作,但我不想用onCreated
vonRendered
的解释来混淆视听。
Template.city.helpers({
places: function() {
const tpl = Template.instance();
const places = tpl && tpl.places.get();
return places || [];
}
});