【问题标题】:How to Upload an Image to Server on Meteor Startup如何在 Meteor 启动时将图像上传到服务器
【发布时间】:2016-05-06 17:02:35
【问题描述】:

我正在尝试为没有/没有上传图像的用户设置默认 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>

现在我已经放弃了这种方法,并考虑上传图像并将 URL 默认附加到所有配置文件(onCreateuser),直到他们更改它。我相信这样做我可能必须在服务器启动时自动上传和图像.请引导我走向正确的方向,因为我仍然是流星中的菜鸟。

存储适配器:GridFS。

问候, 阿扎鲁丁

【问题讨论】:

    标签: javascript meteor spacebars meteor-helper collectionfs


    【解决方案1】:

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

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

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

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

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

    【讨论】:

    • 谢谢"var hello = [{ url: "/images/prof.jpg" }];"成功了。
    猜你喜欢
    • 2016-03-21
    • 1970-01-01
    • 1970-01-01
    • 2020-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-26
    • 2017-12-04
    相关资源
    最近更新 更多