Ryan의 RailsCast on Backbone.js을 Handlebars와 함께 사용하려고하면 간단한 문제가 발생합니다.Backbone.js + 핸들 바 각
JSON 배열을 반복하고 결과를 표시 할 수없는 것처럼 보입니다. 난 내 index.jst.hbs
에서
gem 'backbone-on-rails'
gem 'handlebars_assets'
다음 한
내 Gemfile에이 보석을 사용하고 있습니다 :{{entries.length}}
<ul>
{{#each entries.models}}
<li>{{name}}</li>
{{/each}}
</ul>
API 호출은 7의 카운트에서 볼 수 있듯이, 작동하는 것 같군 스크린 샷
그러나 각 모델의 콘텐츠는 표시되지 않습니다. 아래는 View (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 [email protected], 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
}
]
팁 주셔서 감사합니다. 나는 그것이 어떻게 작동하는지 시험해 볼 것이다. – Dean