Я пытаюсь преобразовать RailsCast Райана на Backbone.jsдля работы с Handlebars и застрял на простой проблеме.
Кажется, я не могу выполнить итерацию по массиву JSON и отобразить результат. Я использую эти драгоценные камни в моем Gemfile
gem 'backbone-on-rails'
gem 'handlebars_assets'
В моем index.jst.hbs
у меня есть следующее:
{{entries.length}}
{{#each entries.models}}
- {{name}}
{{/each}}
Вызов API, кажется, работает, как вы можете видеть по подсчету 7 на скриншоте.
Однако содержимое каждой модели не отображается. Вот представление (index.js.coffee) и ответ JSON ниже.
class Raffler.Views.EntriesIndex extends Backbone.View
template: JST['entries/index']
initialize: ->
#triggered when view gets created, listen to 'reset' event, then re-@render, pass 'this' for context binding
@collection.on('reset', @render, this)
render: ->
$(@el).html(@template(entries: @collection))
this
JSON:
[
{
"created_at":"2012-06-28T18:54:28Z",
"id":1,
"name":"Matz",
"updated_at":"2012-06-28T18:54:28Z",
"winner":null
},
{
"created_at":"2012-06-28T18:54:28Z",
"id":2,
"name":"Yehuda Katz",
"updated_at":"2012-06-28T18:54:28Z",
"winner":null
},
{
"created_at":"2012-06-28T18:54:28Z",
"id":3,
"name":"DHH",
"updated_at":"2012-06-28T18:54:28Z",
"winner":null
},
{
"created_at":"2012-06-28T18:54:28Z",
"id":4,
"name":"Jose Valim",
"updated_at":"2012-06-28T18:54:28Z",
"winner":null
},
{
"created_at":"2012-06-28T18:54:29Z",
"id":5,
"name":"Dr Nic",
"updated_at":"2012-06-28T18:54:29Z",
"winner":null
},
{
"created_at":"2012-06-28T18:54:29Z",
"id":6,
"name":"John Nunemaker",
"updated_at":"2012-06-28T18:54:29Z",
"winner":null
},
{
"created_at":"2012-06-28T18:54:29Z",
"id":7,
"name":"Aaron Patterson",
"updated_at":"2012-06-28T18:54:29Z",
"winner":null
}
]