2012-06-21 19 views
3

也許這種結構不適合流星,也許我正在考慮錯誤。 正試圖在noSQL db中做這樣的關係嗎?在流星中創建與收藏的關係

我有Dropzone和Widget集合。 Dropzone可以有很多小部件,每個小部件可以存在於多個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 

回答

5

我想你想要的東西看起來有點更像是這樣的:

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

助手:

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

這是否幫助?

+0

太棒了,工作! 無論出於何種原因,當模板正在被評估時,我無法將我的頭圍繞在這個值上。事實證明,我正在使它變得更加複雜,然後有必要。 –

+0

是的,它需要一些習慣,但它可以非常棒。 –