gpt4 book ai didi

meteor - 在 Meteor 中创建与集合的关系

转载 作者:行者123 更新时间:2023-12-01 11:51:24 24 4
gpt4 key购买 nike

也许这个结构不适合 Meteor,或者我想错了。尝试在 noSQL 数据库中建立这样的关系不好吗?

我有 Dropzone 和 Widget 集合。一个 Dropzone 可以有很多 widget,每个 widget 可以存在于多个 dropzone 中。

我的问题是我似乎无法让 Handlebars 呈现过滤后的小部件列表。

我的拖放区模型

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

最佳答案

我觉得你想要的看起来更像这样:

  <div class="hotzone">
{{#each widgets}}
{{> widget}}
{{/each}}
</div>

助手:

Template.foo.widgets = -> CC.Widgets.find(dropzones: this._id)

这有帮助吗?

关于meteor - 在 Meteor 中创建与集合的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11147687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com