Note that there are some explanatory texts on larger screens.

plurals
  1. POTypeError: Cannot call method 'bind' of undefined error in Backbone with Django-Tastypie
    primarykey
    data
    text
    <p>I'm writing a simple example to learn Backbone and Django-Tastypie. I'm using Backbone.js 1.0.</p> <p>In the console, when I try <code>notes = new NoteListView();</code> I get the error <code>TypeError: Cannot call method 'bind' of undefined</code>.</p> <p>From what I've read online, I THINK that it's because the template isn't instantiated. But, the template is cached in the template call on the View. So, I'm confused.</p> <p>Maybe my thinking is completely wrong, but what supposed to happen is the bind happens on the template that has been cached so that it can do the set and populate the template.</p> <p>The TastpieCollection and TasttypieModel come from <a href="http://paltman.com/2012/04/30/integration-backbonejs-tastypie/" rel="nofollow">http://paltman.com/2012/04/30/integration-backbonejs-tastypie/</a> which seems to work really well.</p> <pre><code>$(function() { // Note: The model and collection are extended from TastypieModel and TastypieCollection // to handle the parsing and URLs window.Note = TastypieModel.extend({}); window.Notes = TastypieCollection.extend({ model: Note, url: NOTES_API_URL }); window.NoteView = Backbone.View.extend({ template: _.template($('#notes-item').html()), initialize: function () { _.bindAll(this, 'render'); this.model.bind('set', this.render); }, render: function() { this.$el.html(this.template(this.model.toJSON())); return this; } }) window.NoteListView = Backbone.View.extend({ template: _.template($('#notes-item-list').html()), initialize: function () { _.bindAll(this, 'render'); this.collection.bind('set', this.render); }, render: function() { var $notes, collection = this.collection; this.$el.html(this.template()); $notes = this.$('.notes'); collection.each(function(note){ var view = new NoteView({ model: note, collection: collection }); $notes.append(view.render().el); }); return this; } }) }) </code></pre> <p>So, two questions:</p> <p><strong>Question One:</strong> What is the error saying and how do I fix it?</p> <p><strong>Question Two:</strong> The <code>set</code> is the new version of how <code>reset</code> was used... correct?</p> <p>Thanks for your help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload