gpt4 book ai didi

mongodb - 在 Meteor 中使用带有参数的#each

转载 作者:可可西里 更新时间:2023-11-01 09:35:46 24 4
gpt4 key购买 nike

我是 Meteor 框架的新手,我正在尝试使用 meteor + mongo + 空格键显示一些数据。问题是我可能需要使用一个带空格键的参数 #each,但它不允许这样做。

我的代码:

$文件.js

  Template.home.helpers({
places: function() {
return Places.find();
}
});

Template.content.helpers({
images: function() {
return Images.find({});
}
});

$文件.html

<template name="home">    
{{#each places}}
{{>content}}
{{/each}}
</template>

<template name="content">
<li>{{name}} - {{date}}</li>
{{#each images}}
<img src="{{this.url}}">
{{/each}}
</template>

我想做的 - 但它没有用 - 是在 Template.content.helper 函数中使用一个参数,如下所示:

  Template.content.helpers({
images: function(ARG) {
return Images.find({place: ARG});
}
});

在 html 文件中将是

<template name="content">
<li>{{name}} - {{date}}</li>
{{#each images {{name}} }}
<img src="{{this.url}}">
{{/each}}
</template>

你们知道如何正确显示信息吗?我不想显示每个地方的所有信息(图像)。我只想显示那个地方的记者的图像......

提前致谢,马库斯

最佳答案

好的,我可以用下面的代码做我想做的事:

文件.html

<template name="content">
<li>{{name}} - {{date}}</li>
{{#each images name}}
<img src="{{this.url}}">
{{/each}}
</template>

(这意味着我必须删除双括号)

然后在 file.js 中

Template.content.helpers({
images: function(location) {
console.log(location);
return Images.find({"metadata.location": location});
}
});

我希望它也能帮助到其他人。

关于mongodb - 在 Meteor 中使用带有参数的#each,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32041314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com