gpt4 book ai didi

javascript - 我将如何使用cursor.map函数来跳过集合中的第一个项目

转载 作者:行者123 更新时间:2023-12-02 17:19:12 25 4
gpt4 key购买 nike

我有以下模板助手用于输出第一个 {{url}} 和所有 {{thumb}}但是,如果 {{thumb}} 不确定如何在 map 函数中执行此操作,我想跳过第一项。

Template.motionPictures.helpers({
posts: function() {

return Posts.find({}, {fields: {thumb: 1, url: 1}}).map(function(post, index) {
if (index === 0) {
return post;
} else {
delete post.url;
return post;
}
});

}
});

当我对 posts 数组进行 console.log 时,我得到以下内容

enter image description here

这是我所期望的,但我希望数组中的第一个对象仅显示其 {{url}} 而不是 {{thumb}} 到目前为止,所有建议都只是完全删除该对象,或者根本不删除该对象。

最佳答案

您可以使用跳过:

Posts.find({}, {fields: {thumb: 1, url: 1}, skip: 1})..map(fun...

关于javascript - 我将如何使用cursor.map函数来跳过集合中的第一个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24127068/

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