これは私の単純なバックボーンアプリです。私は勉強しています。 (それはcoffeescriptで書かれています)この小さなBackBoneアプリは正しいですか?私は規則を正しく使っていますか?
私はページ(1-1,2-1,1-2,2-2など)のx-yグリッドを持っています。ページが読み込まれ、これらのIDを持つコレクションがインスタンス化されます。ユーザーが(現在のところ左右のみで)ナビゲートすると、表示するHTMLを含めて、モデル全体がサーバーからロードされます。
これはモデルとコレクションとビューが含まれていますが、私は間違った場所で物事をしていることを賭けています!何が間違っているか教えてください。
Page = Backbone.Model.extend
displayHTML: (model, response) ->
$("#content").html(model.get('html'))
Pages = Backbone.Collection.extend
model: Page
url: "/pages"
current_page: '1-1'
initialize: (models, options) ->
this.fetch(success: this.displayFirst)
displayFirst: (collection, response) ->
model = collection.get(collection.current_page)
model.fetch(success: model.displayHTML)
nextPage: ->
id = "#{new Number(this.current_page[2]) + 1}-1" #todo - this will break with 9+
this.gotoPage(id)
previousPage: ->
id = "#{new Number(this.current_page[2]) - 1}-1" #todo - this will break with 9+
this.gotoPage(id)
gotoPage: (id) ->
this.current_page = id
if model = this.get(id)
model.fetch(success: model.displayHTML)
else
alert("Eh nooo")
AppView = Backbone.View.extend
el: $('body')
events:
"click #next-page": "nextPage"
"click #previous-page": "previousPage"
initialize: ->
this.pages = new Pages(null, {view:this})
nextPage: -> this.pages.nextPage()
previousPage: -> this.pages.previousPage()
appView = new AppView
appviewについての好奇心: 'tagName: 'body''を使わないのはなぜですか? – Tjorriemorrie
ヒントをありがとう、非常に便利:) 私が心配していることは、人々はビューレンダリングはモデルの問題ではないと言いましたので、私はそれを変更しようとします。 私の構造が間違っている他のアイデアですか? – Alex