この例の基本バージョンをCoffeeScriptで作成しようとしています:http://davidsulc.com/blog/2012/04/15/a-simple-backbone-marionette-tutorial/。すべての依存関係は、私が(本文に)書き込んだ順序で.coffeeファイルとして宣言され、jQuery+アンダースコア+バックボーン+マリオネットが先頭にあります。
私はモデル、thing.coffeeを持っています
$ ->
console.log 'load model'
class Thing extends Backbone.Model
defaults:
myValue: null
initialize: ->
console.log 'new thing'
window.Thing = Thing
私の最初の問題はスコーピングです。宣言しないwindow.Thing
と、次のファイル(のコレクションThings
、モデルが見つからないThing
など。そこで何が間違っているのでしょうか。
私はコレクション、things.coffeeを持っています
$ ->
console.log 'load collection'
class Things extends Backbone.Collection
model: Thing
window.Things = Things
マリオネットビュー、thing_view.coffeeがあります
$ ->
console.log 'load composite model view'
ThingView = Backbone.Marionette.ItemView.extend(
template: '#template-thing'
tagName: 'tr'
)
window.ThingView = ThingView
マリオネットビュー、things_view.coffeeがあります
$ ->
console.log 'load composite collection view'
ThingsView = Backbone.Marionette.CompositeView.extend(
tagName: 'table'
id: 'things'
template: '#template-things'
itemView: ThingView
appendHtml: (collectionView, itemView) ->
collectionView.$('tbody').append itemView.el
)
window.ThingsView = ThingsView
私はアプリケーションmyapp.coffeeを持っています
$ ->
console.log 'load app'
# Load default data
thingsCollection = new Things([
new Thing(myValue: 'uno'),
new Thing(myValue: 'dos')
])
data:
thingsCollection: thingsCollection
# Create application, specify default layouts
MyApp = new Backbone.Marionette.Application()
MyApp.addRegions singleRegion: '#content'
# On application init...
MyApp.addInitializer (data) ->
console.log 'Init application...'
thingsView = new ThingsView(collection: data.thingsCollection)
MyApp.singleRegion.show data.thingsView
# Start application
MyApp.start data
私のhtmlファイルは次のようになります:
<div id="content">
<script type="text/template" id="template-things">
<thead>
<tr class='header'>
<th>myValue</th>
</tr>
</thead>
<tbody>
</tbody>
</script>
<script type="text/template" id="template-thing">
<td><%= myValue %></td>
</script>
</div>
次のconsole.log
:
load model
load collection
load composite model view
composite collection view
load app
Init application...
Uncaught TypeError: Cannot call method 'render' of undefined
だから、言うまでもなく、私は何が起こっているのか混乱しています-ここにはたくさんの間違いがあると確信していますので、助けてください!