gpt4 book ai didi

javascript - 如何在 Meteor 启动时将图像上传到服务器

转载 作者:行者123 更新时间:2023-11-27 23:24:31 25 4
gpt4 key购买 nike

我正在尝试为没有/未上传图像的用户设置默认 DP。

尝试使用帮助程序显示内容,但收到错误“未捕获错误:{{#each}} 当前仅接受数组、游标或错误值。”下面的代码(客户端JS)JS:

Template.mcomments.helpers({
'mcommentsdata':function(){
return comdata.find({},{sort:{"at":-1}}).fetch();
},

images2: function () {
var fetchimg=Meteor.users.findOne({
"_id":this.__id
});

if((fetchimg.profileimage==undefined)||(fetchimg.profileimage=="")){
var hello="/images/prof.jpg"
return hello;
}else{
return Images.find({"_id":fetchimg.profileimage})


}
}
});

HTML

    <template name="mcomments">
<div id="mcomments" class="col-lg-3">
<div><h5 class="mcommentsheader">Followup Stream </h5>
</div>
<div class="col-lg-12 scrolling comscrolllist" id="mcomments1">
<div id="mcomments2">
{{#each mcommentsdata}}
<div class="col-lg-12 comcontainer">
<div class="row">
<div class="col-lg-3 indcomments" >
{{#each images2}}
<img src="{{this.url
}}" width="45px" height="50px" alt="">
{{/each}}
</div>
<div class="col-lg-9" style="">
<div class="row combody" >
<div class="pull-left mcommfont" >{{user}}</div>
<div class="pull-right mcommcust">{{product}} Case#{{productcaseno}}</div>
</div>
<div class="maincomment">{{comment}}</div>
<div class="comtemp"> <span data-livestamp="{{at}}"></span></div>
</div>
</div>
</div>

<div class="col-lg-12 comblankspace">
</div>
{{/each}}
</div>
</div>
</div>
</template>

现在我已经放弃了这种方法,并考虑上传图像并默认将网址附加到所有配置文件(onCreateuser),直到他们更改它。我相信要做到这一点,我可能必须在服务器启动时自动上传和图像。请引导我走向正确的方向,因为我还是 meteor 新手。

存储适配器:GridFS。

问候,阿扎鲁丁

最佳答案

将“hello”变量更改为以下代码:

var hello = [
{ url: "/images/prof.jpg" }
];

您遇到了问题,因为 hello 当前是一个字符串 - #each 需要一个数组/游标/等。正如您的错误所暗示的那样。

或者,您可以在每个 block 上使用 {{#else}} 并完全摆脱返回“hello”情况:

{{#each images}}
...
{{else}}
<!-- Default profile image code -->
{{/each}}

关于javascript - 如何在 Meteor 启动时将图像上传到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35076421/

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