如何从数据库中获取和显示数据?

时间:2016-03-11 15:33:57

标签: mongodb meteor meteor-collection2

我试图从我的收藏中获取和显示项目。 我创建了模板并为每个项目提供了设计。这是代码:

<template name="list_products">

    {{#each applications}}
        <div class="col-sm-4 col-lg-4 col-md-4">
            <div class="thumbnail">
                <img src="http://placehold.it/320x150" alt="">
                    <div class="caption">
                         <h4 class="pull-right">{{price}}</h4>
                         <h4><a href="#">{{title}}</a>
                                    </h4>
                                    <p>{{description}}</p>
                     </div>
            </div>
        </div>
    {{/each}}
</template>
<。>在.js文件上,我创建了将返回集合中所有项目的应用程序

Template.list_products.applications = function(){
    Products.find();
}

然后我在.html文件中调用了模板

           {{> list_products}}

我运行“npm run start”后出现此错误

Refused to execute script from 'http://localhost:3000/js/jquery.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled
我在做错了什么?我在这里找不到任何步骤?

1 个答案:

答案 0 :(得分:1)

使用助手来做。

    Template.list_products.helpers({
     applications:function(){
      return Products.find({});
      }
    });

再次,你可以遍历应用程序,因为它将返回一个游标。 return Products.find({}).fetch();也可能 但首先尝试使用光标以查看它是否有效。

相关问题