开发者

Rails 3.1 Backbone JST in View will not compile with events

开发者 https://www.devze.com 2023-03-30 01:59 出处:网络
Working with the rails 3.1 asset pipeline and coffeescript. I\'ve used the rails-backbone gem for some generation to help me along and everything has been working well for me until I tried to put even

Working with the rails 3.1 asset pipeline and coffeescript. I've used the rails-backbone gem for some generation to help me along and everything has been working well for me until I tried to put events to my view. As soon as I put anything to the events attribute the JST does not render (it does without it):

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}))

I've also tried an empty events attribute (which doesn't compile unless I put in the empty {}) which does render the JST. I've considered that el is defined as a string instead of a jQuery element (with $()) until the render function. If I do specify:

el: $('#show_listing')

and:

render: ->
  el.html(@template({collection:@collection}))

The JST does not compile.


just a mere typo you got there

instead of

 show_details = ()->                                                                                                                                     
    alert('action') 

it is

  show_details : ()->                                                                                                                                     
    alert('action') 

I am guessing you used shift+enter in textmate for the functions snippet? I have done that, too.

0

精彩评论

暂无评论...
验证码 换一张
取 消