【发布时间】:2013-06-24 22:44:34
【问题描述】:
我似乎无法将点击事件绑定到下面 sn-p 中的操作。有什么想法吗?
var SelectView = Backbone.View.extend({
template: "#select-template",
initialize: function() {
this.render();
},
events: {
"click .placeholder": "optionsDropdown",
},
render: function() {
context = {className: this.className, options: this.model.get("options"), placeholder: this.model.get("placeholder")};
$(this.el).html(getHTML(this.template, context));
},
optionsDropdown: function() {
alert("Hello");
},
});
【问题讨论】:
-
如果在您的
initialize方法中您使用this.$el.on("click", this.optionsDropdown);,它是否有效? -
@Mash:不,我刚试过。由于某种原因,我无法参与其中。
-
你缺少一个目标元素 (el) 我对我的答案进行了更改并添加了一个工作小提琴
-
模型中的数据是什么样的?我怀疑这条线
className: this.className。我在视图定义中的任何地方都看不到className变量
标签: javascript jquery events backbone.js underscore.js