流星#每个块问题

骇客的

我想使用每个块遍历Mongo查询用户的集合。

我有以下html模板,应该从users集合中的配置文件对象中加载不同的数据。

为了明确起见,用户集合具有服务,状态和配置文件对象

    {{#each profile}}
        <div class="profileUser oneDiv">
            <div class="profileUserLeft">
                <div class="profileUserImage">
                    <div class="spin"> {{> spinner}} </div>
                    <img src="{{profile.picturelrg}}" class="profileUserImg">
                </div>
                <div class="profileUserGraph">
                    <label for="myChart"><b>Meetup Graph</b>
                    <br>
                    <span class="profileMonth"> {{profile.month}} </span>
                    <br>
                        <canvas id="myChart"></canvas>
                    </label>
                </div>
            </div>
            <div class="profileUserRight">
                <div class="profileUserName">
                    <ul>
                        <li><h1>{{profile.name}}</h1></li>
                        <li>
                            <div class="circle" style="background-color: {{online.color}}"></div>
                        </li>
                    </ul>
                </div>
        </div>
    </div>
   {{/each}}

这是设置查询的我的助手

profile: function() {
            return Meteor.users.find({
                _id: id
            });
        }

当前,该页面未加载任何数据。

但是,当我静态查询属性时,它可以工作。这样就完成了。

profimg: function() {
            return Meteor.users.find({
                _id: id
            }).fetch()[0].profile.picturelrg;
        }

如何提高效率并使用每个块,而不是使用fetch()方法静态搜索每个不同的属性?

泰国陈

eachBlazefind方法返回CursorMongoDB的同时以数组为参数进行循环您需要做的是fetch游标返回数组

profile: function() {
    return Meteor.users.find({
        _id: id
    }).fetch();
}

但是,您的逻辑不正确。您正在查找与输入ID匹配的配置文件,因此该功能应为

profile: function() {
    return Meteor.users.findOne({
        _id: id
    });
}

然后您可以访问属性而无需each循环

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章