使用rails 3.1资产管道和coffeescript。 我已经使用了rails-backbone宝石一段时间来帮助我,一切都很适合我,直到我试图将事件放到我的视野中。只要我将任何东西放到events属性中,JST就不会渲染(没有它):
Headspace.Views.Shows ||= {}
class Headspace.Views.Shows.IndexView extends Backbone.View
template: JST["backbone/templates/shows/index"]
el: '#show_listing'
initialize: () ->
@collection = @options.collection
this.render()
events:
'click .show_header' : 'show_details'
show_details = ()->
alert('action')
render: ->
$(@el).html(@template({collection:@collection}))
我还尝试了一个空事件属性(除非我放入空{},否则不会编译),它会渲染JST。我认为el被定义为字符串而不是jQuery元素(使用$())直到render函数。如果我指定:
el: $('#show_listing')
和
render: ->
el.html(@template({collection:@collection}))
JST无法编译。
答案 0 :(得分:4)
你到达那里只是一个错字
而不是
show_details = ()->
alert('action')
它是
show_details : ()->
alert('action')
我猜你使用shift +输入textmate作为功能片段?我也是这样做的。