Javascript Meteor:访问呈现回调中的上下文(模板)数据

Javascript Meteor:访问呈现回调中的上下文(模板)数据,javascript,node.js,meteor,meteor-blaze,Javascript,Node.js,Meteor,Meteor Blaze,我有一个带有yield部分的模板: {{>yield}} 在yield中,我正在显示表单,其中的字段填充了当前正在编辑的类别数据: this.route('editCategory', { path: '/panel/category/:_id/edit', layoutTemplate: 'panelTemplate', template: 'editCategoryTemplate', data: function(){ retur

我有一个带有
yield
部分的模板:

  {{>yield}}
yield
中,我正在显示表单,其中的字段填充了当前正在编辑的类别数据:

this.route('editCategory', {
    path: '/panel/category/:_id/edit',
    layoutTemplate: 'panelTemplate',
    template: 'editCategoryTemplate',
    data: function(){
        return Categories.findOne(this.params._id);
    },
});
有一个选择框(我在这里选择父类别),有两个选项。我正在使用脚本选择以前选择的选项:

Template.editCategoryTemplate.rendered = function(){
    $('#categoryParent option[value="'+ this.data.parent +'"]').prop('selected', true);
};
一切正常,但重新加载页面后出现错误:

Exception from Deps afterFlush function: this.data is null

任何帮助都将不胜感激。

最好设置防护装置:

改为使用
this.data.parent
write:

Deps.autorun(function(){
  var parentData = this.data && this.data.parent;
  if(parentData){
    $('#categoryParent option[value="'+ parentData +'"]').prop('selected', true);
  }
})

也许这个页面可以提供一些帮助。我的猜测是,在呈现模板实例时,会调用呈现上的回调函数,但可能还没有检索到数据,因此没有可用的
parent
。我有类似的猜测-但如何解决这个问题?如何强制Meteor等待/检索此数据?(已保存在类别文档集合中)