2017-02-21 73 views
0

我想从流星中的集合中获取数据并使用帮助器将它传递给模板。流星不在html中显示来自集合的数据

这是我在收集代码:

Meteor.publish('displayCustomers', function tasksPublication() { 
    return Customers.find(); 
}); 

下面模板JS文件中的代码

Template.customerlist.onCreated(function() { 
    Meteor.subscribe('displayCustomers'); 
}); 



Template.customerlist.helpers({ 
    displayCustomers :function(){ 
     console.log(Customers.find({})); 
     return Customers.find({}); 
    }, 
}); 

模板:

<template name="customerlist"> 
    <h1>All registered users</h1> 
    {{#each displayCustomers}} 
     {{fname}} 
    {{/each}} 

</template> 

它只是显示HTML内容,即<h1>All registered users</h1>

回答

0

检查您的出版物中返回值到客户端与此MiniMongo chrome extension

+0

我说在客户端的console.log和我一样可以在Firefox –

+0

控制台选项卡中看到你尝试扩展?它会告诉你什么数据订阅正在检索 – mutdmour

0

检查以确保客户在服务器上,并且您发布块只运行在服务器上定义。

另外我会抛出一个调试器到你的onCreated块,以确保你的订阅正在初始化。

除此之外,你的代码看起来很好。我会尝试安装MeteorToys Mongol进行客户端pub/sub调试。 https://atmospherejs.com/msavin/mongol

+0

我在调试器里面添加了发布,发现它不在里面发布从收集js文件。以下是我的完整代码 Meteor.methods({ –

+0

)代码未显示,请尝试编辑您的原始问题。评论具有字符限制。 –

0

你需要在你的模板来实际获取文件:

Template.customerlist.helpers({ 
    displayCustomers :function(){ 
     return Customers.find().fetch(); //will return an array with all published documents 
    }, 
});