我一直在試圖追蹤我的(相當簡單的)Backbone/Coffeescript代碼中的一個奇怪的錯誤。在主幹視圖上沒有「應用」方法
當運行我的應用程序,我得到這個錯誤:
Uncaught TypeError: Object #<IndexView> has no method 'apply'
這裏是我的路由器:
class window.App.Router extends Backbone.Router
initialize: ->
Backbone.history.start({pushState: true})
$(document).on "click", "a:not([data-bypass])", (evt) ->
href = $(this).attr "href"
protocol = this.protocol + "//"
if href.slice(protocol.length) != protocol
evt.preventDefault()
App.navigate(href, true)
routes: {
"": "index",
"artist/:id": "artist",
"albums/:id": "album"
}
index:
@view = new App.IndexView()
和視圖:
class App.IndexView extends Backbone.View
template: "index"
el: $("#container")
initialize: ->
@render()
render: ->
get_template(@el, @template, @domEvents)
domEvents: ->
$("#searchInput").on "change keydown", ->
if $(this).val().length >= 0
$("#placeholder").css("display", "none")
else
$("#placeholder").css("display", "inline-block")
從我的測試,似乎當我擺脫Backbone.history.start({pushState: true})
代碼行時,此錯誤消失。不幸的是,我的應用程序需要pushState,所以消除這個不是一個選項。
有沒有人有什麼想法可能是錯誤的地方?
哇......這樣做...... *嘆息* 我也將Backbone.history.start()移動到新的Router()後面的一行。謝謝一堆! –