Backbone View 事件不会触发
我在项目中使用 Backbone,并且试图使 Backbone 视图的事件功能正常工作。我有以下代码(从我当前的应用程序中提取):
我的基本文件:
window.App =
Models: {}
Views: {}
我的模型:
class App.Models.Story extends Backbone.Model
defaults:
id: null
content: null
我的视图:
class App.Views.Story extends Backbone.View
tagName: "li"
className : "story item"
events:
"click" : "test"
test: ->
alert "TEST"
render: ->
html = "<div> #{@model.get("content")} </div>"
$(@el).html(html)
return this
页面加载时的代码:
$(document).ready ->
story = new App.Models.Story(content: "Some content")
view = new App.Views.Story(model: story)
$("body").append(view.render().el)
元素呈现,但当我单击它时,单击处理程序不执行。我做错了什么?
I am using Backbone in a project and I am trying to get the events functionality of Backbone Views to work correctly. I have the following code (it is extracted out of my current application):
My Base File:
window.App =
Models: {}
Views: {}
My Model:
class App.Models.Story extends Backbone.Model
defaults:
id: null
content: null
My View:
class App.Views.Story extends Backbone.View
tagName: "li"
className : "story item"
events:
"click" : "test"
test: ->
alert "TEST"
render: ->
html = "<div> #{@model.get("content")} </div>"
$(@el).html(html)
return this
The Code on page load:
$(document).ready ->
story = new App.Models.Story(content: "Some content")
view = new App.Views.Story(model: story)
$("body").append(view.render().el)
The element renders but when I click on it, the click handler does not execute. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你会讨厌这个答案......你需要声明
events
而不是event
:You are going to hate this answer... you need to declare
events
notevent
: