이 예제의 기본 버전을 CoffeeScript로 작성하려고합니다 : http://davidsulc.com/blog/2012/04/15/a-simple-backbone-marionette-tutorial/. 모든 의존성은 내가 작성한 순서대로 .coffee 파일로 선언되며 jQuery + Underscore + Backbone + Marionette가 머리에 있습니다. 나는 모델이CoffeeScript/Backbone/Marionette - 자습서 예제 변환 및 범위 지정 문제
, 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
사물의 난 확실히 프로그래머 톤 -
가
load model
load collection
load composite model view
composite collection view
load app
Init application...
Uncaught TypeError: Cannot call method 'render' of undefined
그래서, 무슨 일이 일어나고 있는지에 관해서는 혼란 스러워요 말할 필요도없이 :
<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
에 따라 : 같은
내 html 파일 보인다 여기에 잘못이 있으니 도와주세요!
감사합니다. 왜 창문이 작동하는지 알았지 만 백본이 모델의 전역 네임 스페이스를 자동으로 만들지 않은 이유는 확실하지 않았습니다. 그런 식으로 작동하지 않는다고 생각하세요! 예를 보면 분명히 분명합니다. 예를 들어 "고양이"에 대한 언급이 너무 많아서 js2coffee 이해가 손실 된 것 같습니다. :) –