【发布时间】:2016-05-08 16:49:43
【问题描述】:
我的侧边栏需要从节点集合中加载名称和路径。 我的publication.js
Meteor.publish('nodes', function(){
return Nodes.find();
}); 我的nodes_find.js 和publication.js 文件在服务器文件中
if(Nodes.find().count() === 0){
Nodes.insert({
name: "Example Node",
path: "ExampleNode"
});
Nodes.insert({
name: "Node 2",
path: "ExampleNode"
});
Nodes.insert({
name: "Node 3",
path: "ExampleNode"
});
} 用于显示节点和路径的 Html 块
<template name="sidebar">
<ul class="sidebar-nav" id="sidebar" role="navigation">
<div class="nodes">
{{#each nodes}}
<li>
<a href="{{path}}">
{{name}}
</a>
</li>
{{/each}}
</div>
</ul>
最后是 sidebar.js 文件
Template.sidebar.helpers({
nodes: function(){
return Nodes.find();
}
});
虽然我得到的只是 4 个没有名称和路径的薄标签。 我已经阅读了《发现流星》这本书并进行了练习 已经看到他们如何使用它并查看了许多论坛并看到了这个 确切的代码工作。有什么我遗漏的吗?
【问题讨论】:
-
您订阅了该出版物吗? (或者有自动发布功能?)
-
@bluebird 是的,我已经发布并订阅了。服务器端 Meteor.publish('nodes', function(){ return Nodes.find(); });客户端 Meteor.subscribe('nodes');
标签: meteor meteor-blaze meteor-helper blaze-html