backbone view is triggering the event delegate many times

Hi so I have a view in backbone similar to this

app.FileListItemView = Backbone.View.extend({
    tagName: 'li',
    className: 'list-group-item clearfix',
    events: {
        'click .download-action': 'download'
    template: _.template(
            "<div class='pull-left' style='width: 80%'>\n\
                <%= name %><br><span style='font-size: 10px;'><%= path %></span>\n\
            <div class='pull-right' style='width: 20%'>\n\
                <div class='dropdown'>\n\
                    <button class='btn btn-default dropdown-toggle' type='button' data-toggle='dropdown'>\n\
                      <span class='caret'></span>\n\
                    <ul class='dropdown-menu' role='menu'>\n\
                      <li class='download-action' data-id='<%= id %>' data-accountid='<%= accountid %>' role='presentation'><a class='super-anchor' role='menuitem' tabindex='-1' href='#'>Download</a></li>\n\
    initialize: function () {
    render: function () {
        return this;
    download: function (event) {
        var el = this.$el.find('.download-action');
        var id ='id');
        var accountid ='accountid');
        var url = app.config.get('apiURL');
        var apiKey = app.config.get('apiKey');


        $.ajax(url + '/accounts/' + accountid + '/links', {
            data: {
                'file_id': id, 'direct': true
            headers: {
                Authorization: 'ApiKey ' + apiKey
            type: 'POST',
            success: function (data) {
                if ( {
                    var a = el.find('.super-anchor');
                    //change this part
                    //a.attr('href', data.url).trigger('click');
                    //to this
                    a.attr('href', data.url).on('click', function(event){

the idea is that when I click the LI with "download-action" class the download method is called in my view, that should pick a url from the ajax call and then added to the href attr of the anchot tag which is under the LI and after that I trigger the anchor click, but when I do that the download method start to be called in loop indefinitely, can some how tell me why is this happening?? thanks!!!!


I assume the triggered click event is being propagated up to which then starts the ajax download function all over again. A solution would be to use window.location.href to navigate the user to the new url or to move that link out side

Need Your Help

how do I improve my simple mod_rewrite in htaccess?

.htaccess mod-rewrite

I am using mod_rewrite for clean urls but I'm just having a small problem.

Subtracting values to moment.js using input

javascript jquery html input momentjs

I want to subtract dates to moment.js using input[type="range"] but it's not working correctly. Here is my code:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.