简体   繁体   English

骨干事件映射无法识别类

[英]Backbone Event Map Doesn't Recognize Classes

Stack. 堆。

I'm using Backbone's event map in my View. 我在视图中使用Backbone的事件地图。

JS: JS:

events: {
    "click .edit-info-button": "pullEdits"
},
pullEdits: function(e){
    // Get the value of the button clicked
    e.preventDefault();
    $(".edit-info-button").click(function(){parseEdits(this.value);});
}

HTML: HTML:

<button class="button edit-info-button" value="edit address">EDIT</button>

When edit-info-button is a class, the event listener does not work. 当edit-info-button是一个类时,事件侦听器不起作用。 pullEdits() never fires. pullEdits()永远不会触发。

When I change edit-info-button into an id ("click #edit-info-button", "button id='edit-info-button', etc.) pullEdit() and all functions after it run successfully. 当我将edit-info-button更改为一个id(“单击#edit-info-button”,“ button id ='edit-info-button'等”)pullEdit()及其成功运行后的所有功能。

The issue is, the page I'm working on needs multiple edit buttons and I'd like to give them the same class and pull the value instead of giving them all unique ids. 问题是,我正在处理的页面需要多个编辑按钮,我想给它们提供相同的类并提取值,而不是给它们提供所有唯一的ID。

Am I missing something? 我想念什么吗? Thanks. 谢谢。

Try this instead. 试试这个吧。

...
events: {
    "click .edit-info-button": "pullEdits"
},
pullEdits: function(e){
    var val = $(e.target).attr('value')
    return parseEdits( val );
}
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM