Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9090469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:22:42+00:00 2026-06-16T22:22:42+00:00

I’ve got this backbone code and I cannot figure out why the events in

  • 0

I’ve got this backbone code and I cannot figure out why the events in my view are not working. My application is supposed to be an editable gallery. So I create a view (a Gallery view) within the html element $(#obrazekDetail) and I fetch it with ObrazekViews. I want to trigger events on the ObrazekView and I cannot get it working. Apologies for asking the same type of question again. But I couldn’t find any suitable solution. The backbone JavaScript and HTML code follows:

<table id="obrazekDetail" cellspacing="0" cellpadding="2">
</table>
  <!-- Templates -->
<script type="text/html" id="template-obrazek">
    <tr id="<%= order %>">
        <td><img src="<%= obrazek %>"/>
        </td>
        <td>Nadpis:<input name="nadpis" value="<%= nadpis %>" /></td>
        <td>Popis:<input name="popis" value="<%= nadpis %>" /></td>
        <td><input class="edit" type="submit" name="action" value="Edit" /></td>
        <td><input  class="delete" type="submit" name="action" value="Delete" /></a></td>
    </tr>
</script>

<script type="text/template" id="galerie-template">

</script>

// js code

$(function(){

    window.app = window.app || {};
    window.app.obrazek = new Obrazek();
    window.app.obrazky = new Obrazky();
    window.app.view = new GalerieView();
});


var Obrazek = Backbone.Model.extend({
url : function() {
  return  "/ajax-obrazek/" + this.id + "/";
}
});

var Obrazky = Backbone.Collection.extend({
    model: Obrazek,
    initialFetch: function() {
        var self = this;
        $.each(obrazky_data, function(i, object) {
            var obrazek = new Obrazek();
            obrazek.set({
                id: object.pk,
                nadpis: object.fields.nadpis,
                popis: object.fields.popis,
                order: object.fields.order,
                obrazek: object.fields.obrazek
                 });
            self.model = obrazek;
            self.add(self.model);
        });
    }
});
var ObrazekView = Backbone.View.extend({
    template: _.template($("#template-obrazek").html()),
    events: {
        "click input.edit"   : "edit",
        "click input.delete" : "clear"
    },
    initialize: function() {
        this.model.bind('change', this.render, this);
        this.model.bind('destroy', this.remove, this);
        console.log(this);
    },
    render: function() {
        this.$el.html(this.template(this.model.toJSON()));
        return this;
    },
    clear: function() {
        console.log('test');
      this.model.destroy();
    },
    edit: function() {
            console.log('test');

    }

});
var GalerieView = Backbone.View.extend({
    el: $("#obrazekDetail"),

    initialize: function() {
        window.app.obrazky.bind('add', this.addOne, this);
        window.app.obrazky.bind('reset', this.addAll, this);
        window.app.obrazky.bind('all', this.render, this);
        window.app.obrazky.initialFetch();
    },
    render: function() {
        return this;
    },
    addOne: function(obrazek) {
        var view = new ObrazekView({model: obrazek});
        this.$el.append(view.render().el.innerHTML);
    },
    addAll: function() {
          window.app.obrazky.each(this.addOne);
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:22:43+00:00Added an answer on June 16, 2026 at 10:22 pm

    when u do this this.$el.append(view.render().el.innerHTML); you are extracting the plain html and stripping all events attached to them .
    when u define events using

    events: {
    "click input.edit" : "edit"
    },

    you may think events are directly attached to input.edit but its not. Backbone attaches events to the el and delegates it to child elements matching the selector.So that at run-time if you attach another input.edit element, the event would still work on it.

    So instead just use this conventional way this.$el.append(view.render().el); it maintains all events and gives no surprising results!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.