ここに私のコードです。私が間違っていることや正しいことを教えてください。私はPhishVids
オブジェクトにすべてを格納しようとしています。これが間違ったやり方であれば教えてください。Backbone.jsのビューでJSONデータを取得
JSONは/shows/YEAR.json
に保存されています。年は1987年から2011年までの範囲です。私はJSONを読み込むことができないので、誰かが正しい方向に私を指すことができますか?
var PhishVids = {
Models: {
Show: Backbone.Model.extend({
defaults: {
showid: 'show id',
year: 'year',
month: 'month',
day: 'day',
venue: 'venue'
}
})
},
Views: {
Show: Backbone.View.extend({
el: $('#content'),
initialize: function() {
this.model.fetch();
this.model.bind('change', this.render, this);
},
render: function(event) {
var compiled_template = _.template($("#shows-template").html());
this.el.html(compiled_template(this.model.toJSON()));
return this; //recommended as this enables calls to be chained.
},
events: {
"click .show": "showClick"
},
showClick: function(event) {
}
})
},
Collections: {
ShowList: Backbone.Collection.extend({
parse: function(response) {
return response.items;
}
})
}
};
表示テンプレート:
<script type="text/template" id="shows_template">
<a href='/<%= year %>/<%= month %>/<%= day %>' class='show <%= month %> <%= day %>' id='<%= showid %>'><%= month %>/<%= day %></a>
<div class='venue'><%= venue %></div>
</script>
JSでは '#shows-template'があり、テンプレートには' show_template'があります。 – kubetz
あなたは正しいです、ありがとう。しかし、それは私の問題を完全には解決しません。 – switz