在Meteor中创建与集合的关系

Jon*_*ues 3 handlebars.js meteor

也许这种结构不适合Meteor,或者我认为它错了.试图在noSQL数据库中做这样的关系吗?

我有Dropzone和Widget集合.Dropzone可以包含许多小部件,每个小部件可以存在于多个dropzone中.

我的问题是,我似乎无法使Handlebars呈现已过滤的小部件列表.

我的dropzone模型

dropzone =
  _id: "area1-id"
  title: "Area 1"
Run Code Online (Sandbox Code Playgroud)

小部件模型(缩写)

widget =
  _id: "widget1-id"
  title: "My Widget"
  dropzones: ['area1-id', 'area2-id'] 
  # each widget stores an id of which dropzones it's associated with
Run Code Online (Sandbox Code Playgroud)

相关的模板结构

{{#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}}
Run Code Online (Sandbox Code Playgroud)

辅助功能

# 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
Run Code Online (Sandbox Code Playgroud)

Tom*_*man 5

我想你想要的东西看起来更像这样:

  <div class="hotzone">
    {{#each widgets}}
      {{> widget}}
    {{/each}}
  </div>
Run Code Online (Sandbox Code Playgroud)

帮手:

Template.foo.widgets = -> CC.Widgets.find(dropzones: this._id)
Run Code Online (Sandbox Code Playgroud)

这有帮助吗?