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
4
votes
1 answer

can a backbone.js model contain multiple collections?

I'm just starting out with backbone.js and trying to wrap my head around the modeling concepts. I want to use backbone js to create a shopping cart app, interfacing with a 3rd party REST api (not rails, can't modify). This is the JSON response…
Homan
  • 25,618
  • 22
  • 70
  • 107
4
votes
1 answer

Backbone Collection.add doesn't seem to work

I am building a simple to-do application in backbone. my html is: back bone
Vignesh
  • 315
  • 4
  • 14
3
votes
1 answer

Adding models to collection throws error "Uncaught TypeError: Cannot read property 'idAttribute' of undefined"

I'm having an error trying to add multiple models from the server to a collection. It throws the error: Uncaught TypeError: Cannot read property 'idAttribute' of undefined Here is a test example which gives same error:
aleXela
  • 1,270
  • 2
  • 21
  • 34
3
votes
2 answers

Find model which doesnt have an attribute in Backbone collection

I know that we can find all models in collection like so, based on attributes var friends = new Backbone.Collection([ {name: "Athos", job: "Musketeer"}, {name: "Porthos", job: "Musketeer"}, {name:…
3
votes
2 answers

How to convert an array to Collection in backbone

I have an array defined as: this.noOfHouseHold = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"]; I'm trying to convert it to a Backbone Collection as: var adultListCollection = new…
3
votes
1 answer

Non-destructive backbone collection filtering

I want to filter a Backbone collection based on one or more of it's model's properties. I've read around the problem and I've noticed that the most discussed solution is to simply use this.where({"applicationType": application}); to filter and then…
3
votes
1 answer

Backbone Collection fetch() method override previous models on repeat call

I'm using backbone.js Collection fetch method to send request to return data based on offset and limit. First collection.fetch() method returns 5 models because LIMIT 0 and LIMIT 5 , and while calling again…
3
votes
1 answer

how to add the model to collection without duplicating?

var collection = new Backbone.Collection([ {key:1,name: "Tim", age: 5}, {key:2,name: "Ida", age: 26}, {key:3,name: "Rob", age: 55} ]); i am going to add the model {key:4,name: "Rob", age: 55} Here since the key is different, backbone will…
Aravinth Raja
  • 429
  • 4
  • 9
3
votes
1 answer

Backbone Marionette.js reqres framework doesn't wait for collection to get populated

I'm using Backbone.Marionette's request-response framework to fetch data in collection and then response it to the request object that request it, but obviously it doesn't wait for collection to get populated. And here is my code: This is where it…
3
votes
1 answer

Backbone: Inherited Models not working in Collection with ID

I've run into this problem as I think I'm understanding Backbone incorrectly. I have a super class called Runnable and a set of sub classes inherited from it: var Runnable = Backbone.Model.extend({ template: $("#template"), defaults:…
3
votes
1 answer

Wrong collection.length when passing JSON array to Backbone Collection

I'm new to Backbone, and I'm very confused about what's happening when I pass a JSON array (of objects) to a Backbone Collection. I'm fetching some JSON from a spreadsheet hosted on Google Drive. I'm parsing that data, as the actual data that I want…
3
votes
1 answer

BackboneJs: Creating multiple models in a collection from a nested object

{ "code":"OK", "message":"Success", "errorFlag":"N", "errors":null, "data": { "images": { 0: img0, 1: img1, 2: img2 } } } This is a REST response and I wanted to put the…
Barry
  • 1,587
  • 2
  • 13
  • 19
3
votes
2 answers

Typescript type checking - Backbone.Model instance cannot be type checked

I'm having a problem with Typescript and Backbone collections. Here's some groundwork: class BaseChartModel extends Backbone.Model { } class ScatterPlotModel extends BaseChartModel { } class BarChartModel extends BaseChartModel { } class…
parliament
  • 21,544
  • 38
  • 148
  • 238
3
votes
2 answers

Bind a view to collections in backbone.js

I'm semi-new to backbone. I'm trying to bind a collection to a view so that when a new model is added to a collection, the view is updated. I think when you do this with models you can bind to the model's change event. But how do you do the same…
3
votes
2 answers

How to clone models from Backbone collection to another

I need to clone the models in one backbone collection and add then add them to another. (IOW all of the models in the new collection need to be unique, and have no connection to the models in the original collection.) Here is my…