Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone.js results of fetch doubling
    text
    copied!<p>I am trying to use Django and tastypie with backbone.js and mustache. I have set up an example to study those. When using the below code I get results of users doubling as:</p> <ul> <li>-Id User name</li> <li>-1 yol</li> <li>-2 dada</li> <li>-1 yol</li> <li>-2 dada</li> </ul> <p>--- MY CODE ---</p> <pre class="lang-js prettyprint-override"><code>// I think this tastypie adjustment is not related with the problem but i want you to see the //whole code window.TastypieModel = Backbone.Model.extend({ base_url: function() { var temp_url = Backbone.Model.prototype.url.call(this); return (temp_url.charAt(temp_url.length - 1) == '/' ? temp_url : temp_url+'/'); }, url: function() { return this.base_url(); } }); window.TastypieCollection = Backbone.Collection.extend({ parse: function(response) { this.recent_meta = response.meta || {}; return response.objects || response; } }); (function($){ // MODELS-COLLECTIOS //USERS var User = TastypieModel.extend({ url: USERS_API }); var Users = TastypieCollection.extend({ model: User, url:USERS_API }); //VIEWS var UsersView = Backbone.View.extend({ render: function(){ // template with ICanHaz.js (ich) this.el = ich.userRowTpl(this.model.toJSON()); return this; } }); //main app var AppView = Backbone.View.extend({ tagName: 'tbody', initialize: function() { this.users = new Users(); this.users.bind('all', this.render, this); this.users.fetch(); }, render: function () { // template with ICanHaz.js (ich) this.users.each(function (user) { $(this.el).append(new UsersView({model: user}).render().el); }, this); return this; } }); var app = new AppView(); $('#app').append(app.render().el); })(jQuery); </code></pre>
 

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