【发布时间】:2016-03-11 15:33:56
【问题描述】:
我正在尝试从我的收藏中获取并显示这些项目。 我创建了模板并为每个项目提供了设计。代码如下:
<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
我做错了什么?这里缺少任何步骤吗?
【问题讨论】:
-
问题是什么都不显示还是数据有误?如果你打开一个控制台,
Products.find().count()会给你什么? -
我猜你的问题可能是
Template.list_products.applications部分。试试Template.list_products.helpers.applications = function(){ Products.find(); }。我假设您已经自动发布或已经发布了。 -
@DavidWeldon 我得到了 3,集合中的文档数
-
@Oscar 好的,现在试试
-
@Oscar 没用。 t 没有自动发布,我没有发布。我将我的集合放在 /lib 目录中,以供客户端和服务器访问。我还需要发布和订阅吗?
标签: mongodb meteor meteor-collection2