Questions tagged [backbone.js-collections]

For Backbone questions specific to Backbone's collections.

Backbone collections are order sets of models. Collections forward events on their models to the collection's listeners for convenience.

523 questions
48
votes
4 answers

How to find a model from a collection according to some attribute other than the ID?

I have a model with several object: //Model Friend = Backbone.Model.extend({ //Create a model to hold friend attribute name: null, }); //objects var f1 = new Friend({ name: "Lee" }); var f2 = new Friend({ name: "David"}); var f3 = new…
Anar
  • 925
  • 2
  • 8
  • 15
46
votes
3 answers

Saving jQuery UI Sortable's order to Backbone.js Collection

I have a Backbone.js collection that I would like to be able to sort using jQuery UI's Sortable. Nothing fancy, I just have a list that I would like to be able to sort. The problem is that I'm not sure how to get the current order of items after…
VirtuosiMedia
  • 52,016
  • 21
  • 93
  • 140
45
votes
2 answers

Backbone.js collection options

I have written a model/view/collection using Backbone.js. My collection uses the fetch method to load the models from a remote server. The url required for this collection needs an id like: messages/{id}. But I have found no clean way to pass…
Jens
  • 1,499
  • 3
  • 17
  • 28
43
votes
2 answers

Filter backbone collection by attribute value

I have a defined model and a collection: var Box = Backbone.Model.extend({ defaults: { x: 0, y: 0, w: 1, h: 1, color: "black" } }); var Boxes = Backbone.Collection.extend({ model: Box }); When…
rpabon
  • 1,191
  • 2
  • 16
  • 22
33
votes
4 answers

Best practice for saving an entire collection?

Say that I have a Collection and I've made changes to many of its Models. What's the best way to save all of the changes using a single HTTP request?
a paid nerd
  • 30,702
  • 30
  • 134
  • 179
29
votes
4 answers

Fetch a collection using a POST request?

I have managed to work with REST API's to fetch() data where the urls contain minimal parameters (and use GET). How would one retrieve a collection through a POST request?
mike
  • 8,041
  • 19
  • 53
  • 68
18
votes
5 answers

set attribute of all models in backbone collection

I understand that using pluck method we can get an array of attributes of each model inside a backbone collection var idsInCollection = collection.pluck('id'); // outputs ["id1","id2"...] I want to if there is a method that sets up an attribute to…
sublime
  • 4,013
  • 9
  • 53
  • 92
17
votes
1 answer

backbone.js collection view example using marionette template

Can you please suggest me some example for showing list view through marionette template system. Basically, I have a marionette template and based on the template i am creating a table list.
kulls
  • 845
  • 2
  • 12
  • 37
16
votes
5 answers

How to pluck a Backbone collection's attribute

I want to create an array of specific attribute values from a Backbone collection. var days = _.select( this.collection.models, function(model) { return model.attributes.type === 'session'; } ); days = _.pluck(days,…
13
votes
2 answers

How to place a collection within a model in Backbone.js?

I would like some insight on how one would add structure a collection within a model. My simple app has teams (so a team model and collection of teams) and each team has a bunch of players(player model and player collections). So a visual structure…
Charles
  • 638
  • 2
  • 9
  • 23
13
votes
2 answers

Backbone.js - How to get an array of object literals out of a collection?

I'm trying to keep an array of object literals in sync with server data. These objects are being placed on a Google map via backbone.googlemaps extension. I have a collection: var LocationList = Backbone.Collection.extend({ model: Location, url:…
professormeowingtons
  • 3,504
  • 7
  • 36
  • 50
13
votes
1 answer

Find model in Backbone.js collection by cid rather than id

Can I use Collection.get(id) to find a model within a Backbone.js collection by cid, for a model not yet saved to the server? From the documentation, it seems like .get should find a model by either its id or cid. However, collection.get(cid)…
prototype
  • 7,249
  • 15
  • 60
  • 94
13
votes
4 answers

Backbone Collection with multiple models?

I'm learning Backbone. I want to create a list that can contain different models, with different attributes. For example, listing folder contents, which could include models of type file and models of type folder, in any order. file : { title :…
user1031947
  • 6,294
  • 16
  • 55
  • 88
12
votes
3 answers

For Loop over Backbone Collection

Fairly new to backbone, so this is a really basic question. I have a Backbone collection passed into a function and I can prove that it has been passed and that the models in the collection have ids. Here's how I'm setting the ids -…
praks5432
  • 7,246
  • 32
  • 91
  • 156
11
votes
1 answer

Backbone nested collection

I have an app in backbone that retrieve data from a server. This data are hotels and foreach hotel I have more rooms. I have divided hotel into a json and rooms inside another json like this: hotel.json [ { "id": "1", "name": "Hotel1" …
Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
1
2 3
34 35