也许这种结构不适合 Meteor,或者我想错了。试图在 noSQL 数据库中建立这样的关系吗?
我有 Dropzone 和 Widget 集合。一个 Dropzone 可以有许多小部件,并且每个小部件可以存在于多个 dropzone 中。
我的问题是我似乎无法让 Handlebars 呈现过滤后的小部件列表。
我的 dropzone 模型
dropzone =
_id: "area1-id"
title: "Area 1"
小部件模型(缩写)
widget =
_id: "widget1-id"
title: "My Widget"
dropzones: ['area1-id', 'area2-id']
# each widget stores an id of which dropzones it's associated with
相关模板结构
{{#each dropzones}}
<div class="dropzone span4">
<h1>{{title}}</h1>
<div class="widget-area">
<div class="hotzone">
{{#widgets _id}} # passing in the current dropzone id
{{/widgets}}
</div>
</div>
</div>
{{/each}}
辅助函数
# returns the correct sets of widgets, but can't figure
# out how to make it render the widget partial
Handlebars.registerHelper 'widgets', (drop_id)->
widgets = CC.Widgets.find(dropzones: drop_id)
_.each widgets, (widget)->
Template.widget(widget) # this ends up being blank with no error