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 7175791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:22:31+00:00 2026-05-28T16:22:31+00:00

I have a view and collection like this: window.DmnView = Backbone.View.extend({ template: _.template($(#tmpl_dmnListItem).html()), events:

  • 0

I have a view and collection like this:

window.DmnView = Backbone.View.extend({
    template: _.template($("#tmpl_dmnListItem").html()),
    events: {
        "click .getWhois": "showWhois",
        "click .getDomain": "toBasket"
    },
    initialize: function() {
        this.model.bind('change', this.render, this);
        this.model.bind('destroy', this.remove, this);
    },
    render: function() {
        return $(this.el)
                .attr("class", this.model.get("free") ? "dmnItem green" : this.model.get("checked") ? "dmnItem red" : "dmnItem red loader")
                .html(this.template(this.model.toJSON()));
    },
    remove: function() {
        $(this.el).remove();
    },
    showWhois: function() {
        showBoxes(this.model.get("info"));
        return false;
    },
    toBasket: function() {
        this.model.toBasket();
        console.log("view");
    }
});

window.DmnListApp = Backbone.View.extend({
    el: $("#regWrap"),
    events: {
        "keypress #dmnName": "checkAll"
    },
    initialize: function() {
        this.input = this.$("#dmnName");
        this.list = this.$("#dmnList");
        this.basket = this.$("#dmnBasket");
        dmnList.bind('add', this.addOne, this);
        dmnList.bind('all', this.render, this);
        DmnView.bind('toBasket', this.toBasket, this);
    },
    render: function() {

    },
    addOne: function(dmnItem) {
        var view = new DmnView({model : dmnItem});
        this.list.append(view.render());
    },
    checkOne: function(name, zone, price, days) {
        dmnList.create({name: name, zone: zone, price: price, days: days});
    },
    checkAll: function(e) {
        var name = this.input.val();
        if (!name || e.keyCode != 13) return;
        if (name == "")
            name = "yandex";
        dmnList.destroyAll();
        var zoneList = dmnList.domainsInfo.Name;
        var costList = dmnList.domainsInfo.CostOrder;
        var daysList = dmnList.domainsInfo.DaysToProlong;
        var parent = this;
        $.each(zoneList, function(key, zone) {
            parent.checkOne(name, zone, costList[key], daysList[key]);
        });
        this.input.val("");
    },
    toBasket: function(){
        console.log("collection");
    }
});

I want Collection’s method toBasket() to be called after View’s method toBasket() was called. For this purpose I do the following in Collection:

DmnView.bind('toBasket', this.toBasket, this);

So, if this worked, I should receive two messages in my javascript console:

  1. view
  2. collection

(Maybe in other order)

But I only see “view” message in console. What I do wrong?

TIA!

  • 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-05-28T16:22:32+00:00Added an answer on May 28, 2026 at 4:22 pm

    You’re almost there. In your collection view, you’re attempting to listen to the DmnView event toBasket, but how you have it setup is a little incorrect. To listen to events, you have to bind to a specific instance you want to listen to, not a class. So you’ll want to move the bind from initialize to addOne, like this:

    window.DmnListApp = Backbone.View.extend({
        // ...
        initialize: function() {
            this.input = this.$("#dmnName");
            this.list = this.$("#dmnList");
            this.basket = this.$("#dmnBasket");
            dmnList.bind('add', this.addOne, this);
            dmnList.bind('all', this.render, this);
            // Remove the DmnView bind here
        },
        addOne: function(dmnItem) {
            var view = new DmnView({model : dmnItem});
            // Bind to the DmnView instance here
            view.bind('toBasket', this.toBasket, this);
            this.list.append(view.render());
        },
        // ...
    });
    

    Now that your collection view is listening for the event toBasket, you need to actually fire the event in your DmnView view.

    In Backbone views, no events are automatically fired, so you’ll need to manually trigger it yourself, like this:

    window.DmnView = Backbone.View.extend({
        // ...
        toBasket: function() {
            this.model.toBasket();
            console.log("view");
    
            // Trigger the event
            this.trigger('toBasket');
        }
    });
    

    You should now see both messages in your console.

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

Sidebar

Related Questions

I have a Backbone View that has a Collection as its Model. If the
I use backbone.js and have a model without a collection. In the view I
TL;DR Is PinView.prototype = _.extend(PinView.prototype, google.maps.OverlayView.prototype) the proper way to have a Backbone View
I have a view that's doing a fetch() to a collection and returning some
I have a list view that displays a collection of items, each item has
i have view like 'home/details/5', it can be access by anonymous user. but there
I have view stack in a app like so: <mx:ViewStack id=viewStack left=0 right=0 top=0
As in the backbone-todolist example,I have a collection of elements. I made 2 views,
I have a MainWindow that contains a window with a TreeView. The tree view
I have this form in my view: <!-- Bug (extra 'i') right here-----------v -->

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.