View 中的 Rails 3.1 Backbone JST 不会使用事件进行编译
使用 Rails 3.1 asset pipeline 和 Coffeescript。 我已经使用了 Rails-backbone gem 几代人来帮助我,一切都对我来说运行良好,直到我尝试将事件放入我的视图中。一旦我将任何内容添加到 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}))
我还尝试了一个空的 events 属性(除非我放入空的 {} ,否则它不会编译),它会渲染日本标准时间。我认为 el 被定义为字符串而不是 jQuery 元素(使用 $()),直到渲染函数为止。如果我指定:
el: $('#show_listing')
和:
render: ->
el.html(@template({collection:@collection}))
JST 不会编译。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是你在那里的一个拼写错误,
而不是
我
猜你在 textmate 中使用了 shift+enter 作为函数片段?我也这么做过。
just a mere typo you got there
instead of
it is
I am guessing you used shift+enter in textmate for the functions snippet? I have done that, too.