Meteor 无法呈现两个集合中的数组
正在尝试构建一个应用程序,就像这样 该应用程序有两个集合 电影Meteor 无法呈现两个集合中的数组,meteor,Meteor,正在尝试构建一个应用程序,就像这样 该应用程序有两个集合 电影 { "_id" : "S7mGgtJhiQ3GZavqn", "cast_id" : [ "pBnAFGaxNGLkDGuPk", "7HZkmd6BofNmjXRyw" ], "date" : "31-May-2014", "name" : "Rakshak", "vote" : 4 } 演员阵容 { "_id" : "pBnAFGaxNG
{
"_id" : "S7mGgtJhiQ3GZavqn",
"cast_id" : [
"pBnAFGaxNGLkDGuPk",
"7HZkmd6BofNmjXRyw"
],
"date" : "31-May-2014",
"name" : "Rakshak",
"vote" : 4
}
演员阵容
{
"_id" : "pBnAFGaxNGLkDGuPk",
"link" : "http://en.wikipedia.org/wiki/Poonam_Dhillon",
"name" : "Poonam Dhillon"
}
{
"_id" : "7HZkmd6BofNmjXRyw",
"link" : "http://en.wikipedia.org/wiki/Rishi_Kapoor",
"name" : "Rishi Kapoor"
}
我已经写了模板,就像这样
<template name="movies">
{{#each movies}}
{{> movie}}
{{/each}}
</template>
<template name="movie">
{{> vote}}
<h3><span class="name"><b>{{name}}</b></span><br></h3>
<span class="date"><b>Release Date:</b> {{date}}</span><br>
<span class="cast"><b>Cast:</b></span>
{{#each casts}}
{{> cast}}
{{/each}}
<br>
</template>
<template name="casts">
{{#each cast}}
<a href="{{link}}">{{name}}</a>,
{{/each}}
</template>
我已经尝试了很多,但无法在演员名单中显示演员的链接。你的代码不起作用,因为你没有在电影对象上使用演员id数组。 相反,您尝试查找与电影相关联的_id的演员阵容。在电影模板帮助器中,数据上下文设置为电影对象 相反,您应该为强制转换模板的强制转换id条目设置数据上下文,如下所示: 电影模板:
{{#each cast_id}}
{{> cast }}
{{/each}}
铸造模板:
{{#with getCast}}
DostuffwithData from getCast
{{/with}}
getCast模板帮助程序:
Template.cast.getCast = function () {
return Cast.find(this);
}
要使您的示例正常工作,几乎不需要修复,因此我决定创建QuickMeteor项目: 结果: 固定代码:
<template name="cast">
<a href="{{link}}">{{name}}</a>,
</template>
Template.movie.helpers({
casts : function () {
console.log("inside movie.helpers");
console.log(this);
return Casts.find({_id: {$in:this.cast_id}}) ;
}
});
,
Template.movie.helpers({
强制类型转换:函数(){
console.log(“insidemovie.helpers”);
console.log(this);
返回Casts.find({u id:{$in:this.cast\u id}});
}
});
<template name="cast">
<a href="{{link}}">{{name}}</a>,
</template>
Template.movie.helpers({
casts : function () {
console.log("inside movie.helpers");
console.log(this);
return Casts.find({_id: {$in:this.cast_id}}) ;
}
});