何らかの理由で、Backbone アプリでビューを複数回インスタンス化できません。私は与えられてundefined is not a function
います。なぜでしょうか?
app.coffee
define [
'views/start'
], (
StartView
) ->
initialize = ->
# Take us to the start view
startView = new StartView()
startView.render() # Works just fine
initialize: initialize
ビュー/start.coffee
define [
'jquery'
'underscore'
'backbone'
'text!templates/start.html'
'views/question'
], (
$
_
Backbone
StartTemplate
QuestionView
) ->
StartView = Backbone.View.extend
events:
'click #btn-begin': 'pushQuestionView'
render: ->
# Create a template and stuff it into the view element
@$el.html @template = _.template StartTemplate
# Inject the HTML in the document
$('#main').html @el
# Return view for chaining
@
pushQuestionView: ->
questionView = new QuestionView()
questionView.render()
StartView
ビュー/質問.コーヒー
define [
'jquery'
'underscore'
'backbone'
'text!templates/question.html'
'views/form'
'views/start'
], (
$
_
Backbone
QuestionTemplate
FormView
StartView
) ->
QuestionView = Backbone.View.extend
events:
'click #btn-prev': 'goBack'
render: ->
# Create a template and stuff it into the view element
@$el.html @template = _.template QuestionTemplate
# Inject the HTML in the document
$('#main').html @$el
# Return for chaining
@
goBack: ->
console.log StartView # => undefined
startView = new StartView() # => Uncaught TypeError: undefined is not a function
startView.render()
QuestionView
初めて機能したので、構文エラーになることはありません。