FAQ Database Discussion Community


Best method for rendering collection in Backbone

javascript,backbone.js,backbone-collections
I'm using Backbone and I have the following model and collection App.Models.Person = Backbone.Model.extend({ }); App.Collections.People = Backbone.Collection.extend({ model: App.Models.Person, url: 'api/people', }); However what I'm struggling on is the best way to render this collection. Here's how I've done it so far which works but doesn't seem to be...

Casting Backbone Collection object to its original type

javascript,jquery,backbone.js,backbone-collections
I use backbone js to add custom elements to a backbone js Collection . I need to cast it back to its original type below is the var Text = function () { }; var Radio = function () { }; function myfunction() { var collection = new Backbone.Collection(); var...

Backbone.js remove model from collection

javascript,backbone.js,backbone-collections
I'm learning Backbone and for the life of me I can't remove a model from a collection. The collection 'remove' event fires, but the collection appears to remain the same. Here's what I have so far: http://jsbin.com/becamo/edit?js,output I remove the model from the collection upon click. Then, the list view...

How to render a Backbone collection with headers between items

javascript,backbone.js,timeline,backbone-collections
I have a Backbone collection in my app that is basically a timeline. Every item in the collection has a date field and the collection is sorted by it. Items are dynamically loaded and added to this collection (when scolling). I want to render this collection, but I also need...

Collection - Model usage for JSON response?

json,backbone.js,backbone-collections
Regarding the pattern Backbone uses for Collections and Models , I am not sure if what I am trying to achieve is possible. I am wanting the Collection to act as a constructor by making a AJAX POST request to fetch JSON. Using that JSON response it will instantiate multiple...

Backbone JS - Combination of collection, views and models

backbone.js,backbone-views,backbone-collections,backbone-model
I had the following setup now in three different projects, so I thought maybe it's worth asking here. There's a chance I'm not the only guy wondering about this. So there it comes: I have a list of objects The list items have a special function like draggable or onClick-Events...

Error retrieving models from backbone collections once there is idAttribute = '_id'

backbone.js,backbone-collections,backbone-model
I have a Model user set to be like this: User = Backbone.Model.extend({ urlRoot: '/users', defaults: { id: '', username: '', password: '' }, idAttribute: '_id', initialize: function () { console.log('User initiated'); } }); And Collection to be like this: var Users = Backbone.Collection.extend({ url: "/users", model: User, }); Users...

Change event fired instead reset in backbone view

javascript,backbone.js,backbone-views,backbone-events,backbone-collections
I'm trying to execute my reset event in view through cllection fetch but it doesn't working... router: var tablesCollection = new TablesCollection(); var tablesView = new TablesView({ collection: tablesCollection}); tablesCollection.fetch({ reset: true }); My view: initialize: function(){ _.bindAll(this); this.collection.bind('reset', this.render); this.collection.bind('add', this.addTable); this.collection.bind('change', this.changeTable); this.collection.bind('destroy', this.delTable); }, render: function() {...

Backbone model which I see in success callback and error callback is different. #Backbone save

backbone.js,jquery-callback,backbone-collections,backbone-model
I have a backbone model which has Backbone Collections in it. When I save the model and if it is success then my model object is properly structured as it was. But when error occurs (say validation error), in error callback the model object is modified (Collections inside model object...

Backbone Performance - Collection with a view per model or only one view for the whole collection

performance,backbone.js,backbone-views,backbone-collections,backbone-model
If a have a collection with 50 models, it seems that I have 2 main options to render a list displaying 50 models: - Option1 : Create a specific "item view" for each model and append these views to a main "list view". This will provide a direct relationship between...