I am a bit confused about what this should be in a template helper.
I have a following document: meeting
{"matches":["J6RbxgZaB6thX3Db5","QzdkaAJkBywwAa6rA","8e939ebZ9vmr9vbo5","r6ExKfumkytAdwPHs"],"start_time":"2015-08-07T09:24:27.466Z","_id":"6qfcj3fo6yvbnd9y7"}
templates
<template name="session">
<table>
<tr>
<th>A Front</th>
<th>B Front</th>
<th>Result</th>
</tr>
{{#each meeting.matches}}
{{> scorerow }}
{{/each}}
</table>
</template>
<template name="scorerow">
<tr>
<td><input value="{{a_front}}"/></td>
<td><input value="{{b_front}}" /></td>
<td><input size="2" /> – <input size="2" /></td>
</tr>
</template>
Helpers
Template.session.helpers
meeting: ->
Meeting.findOne FlowRouter.getParam 'sessionId'
Template.scorerow.helpers
'a_front': ->
log this
matchupId=JSON.stringify(this)
log matchupId
res = Matchup.find({_id:matchupId}).fetch()
log "Matchup: %o", res
return 'boo' unless res
log "%s: %o", matchupId, res
return res.a_front
And I get the following log (treat log as an alias for console.log)
String {0: "r", 1: "6", 2: "E", 3: "x", 4: "K", 5: "f", 6: "u", 7: "m", 8: "k", 9: "y", 10: "t", 11: "A", 12: "d", 13: "w", 14: "P", 15: "H", 16: "s", length: 17, [[PrimitiveValue]]: "r6ExKfumkytAdwPHs"}
utils.coffee:1 "r6ExKfumkytAdwPHs"
utils.coffee:1 Matchup: []
utils.coffee:1 "r6ExKfumkytAdwPHs": []
However, after typing on the console:
>>Matchup.findOne("r6ExKfumkytAdwPHs")
Object {_id: "r6ExKfumkytAdwPHs", a_fwd: "8FtzATa2J93qxRW5C", a_bck: "4vQYoRpGZ9PLrvD5r", b_fwd: "H7skjaLr84Pvi396A", b_bck: "5KZsuKvC6zehPPLCP"…}
What could be the problem, and how to iterate over the Matchups?
thanks
ps using coffeescript and FlowRouter, if matters
Ok, found one typo, JSON.stringify will have quotes, that’s why it doesn’t work.