Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 流星/火焰渲染:{{each}}在另一个{{each}}中不';t返回正确的数据(数据上下文)_Templates_Meteor_Meteor Blaze_Helpers - Fatal编程技术网

Templates 流星/火焰渲染:{{each}}在另一个{{each}}中不';t返回正确的数据(数据上下文)

Templates 流星/火焰渲染:{{each}}在另一个{{each}}中不';t返回正确的数据(数据上下文),templates,meteor,meteor-blaze,helpers,Templates,Meteor,Meteor Blaze,Helpers,我想知道你是否能给我一些解决这个“问题”的线索。我是JS(+Meteor)的新手,所以对你来说可能非常简单。我正在使用helpers和blaze/spacebar进行渲染 我有一个简单的助手: Template.monitoring.helpers({ 'realtime': function(){ return { house: house.find( {} ), neighbours: neighbours.fi

我想知道你是否能给我一些解决这个“问题”的线索。我是JS(+Meteor)的新手,所以对你来说可能非常简单。我正在使用
helpers
blaze/spacebar
进行渲染

我有一个简单的助手:

Template.monitoring.helpers({

    'realtime': function(){
        return {
            house:    house.find( {} ),
            neighbours: neighbours.find( {} ),
        }
    } // end of realtime

}); // end of helpers
在这一点上,一切都很好。我能够检索到我想要的数据。问题是我不能像我想要的那样渲染它。在我的
模板下方

<template name="monitoring">

   {{#each realtime.house}}
   <div class="card red">
     SHOW STUFF ABOUT HOUSE
   </div>

    <div class="card blue">
        {{#each realtime.neighbours}}
        SHOW STUFF ABOUT NEIGHBOURS OF THE SPECIFIC HOUSE
        {{/each}}
  </div>

  {{/each}} -> end of each realtime.house

</template>

{{{#每个realtime.house}
展示房子的东西
{{{#每个实时邻居}
展示特定房子邻居的资料
{{/每个}}
{{/each}->每个realtime.house的结尾
更准确地说,当呈现我的模板时:

  • 红牌数量=房屋数量=>完美
  • 每张红牌都包含一张house=>perfect的数据

  • 蓝卡数量=房屋数量=>完美

  • 每个蓝卡都包含所有邻居的数据=>错误。我想要的是邻居关于具体房子的数据
你知道如何在合适的地方买到合适的东西吗?
非常感谢。

您需要两位助手:一位归还房屋,另一位归还邻居的房屋作为背景。没有这个模式,我无法给出精确的答案,但是让我们假设每个邻居都有一个连接这两个属性的
houseId
属性

Template.monitoring.helpers({
房屋:功能(){
返回house.find();
},
邻居:函数(){
//注意这里的上下文是一所房子,因为它是
//从一个内部调用。
返回邻居。查找({houseId:this.\u id});
},
});
您的模板将如下所示(假设每个邻居都有一张蓝色卡片):


{{{#每个房子}
展示房子的东西
{{{每个邻居}
展示特定房子邻居的资料
{{/每个}}
{{/每个}}