How to use the Collection function from backbone

Find comprehensive JavaScript backbone.Collection code examples handpicked from public code repositorys.

30
31
32
33
34
35
36
37
38
39
this._layersFactory = options.layersFactory;

attrs = attrs || {};

this.layers = options.layersCollection || new Layers();
this.geometries = new Backbone.Collection();

var center = attrs.center || this.defaults.center;
if (typeof center === 'string') {
  center = JSON.parse(center);
fork icon272
star icon419
watch icon115

+ 7 other calls in file

17
18
19
20
21
22
23
24
25
26

describe("backbone configuration", function () {
  beforeEach(function () {
    this.Model = Backbone.Model.extend({url: 'url'});
    this.model = new this.Model({ id: 1, value: 1 });
    this.collection = new Backbone.Collection();
    this.collection.add(this.model);
  });

  it("getKey should return the result of the url, by default", function () {
fork icon10
star icon58
watch icon59

+ 3 other calls in file

172
173
174
175
176
177
178
179
180
181
```javascript
var Backbone = require('backbone');
var WidgetModel = require('./models/widget')

// Our main export from this module (just the collection)
module.exports = Backbone.Collection.extend({
  // Specify the model type for this collection
  model: WidgetModel,
  // The RESTful API URL representing this resource
  url: '/widgets'
fork icon7
star icon80
watch icon11

38
39
40
41
42
43
44
45
46
47
  Backbone.sync('update', this, options);
},

toJSON: function () {
  return {
    layers: Backbone.Collection.prototype.toJSON.apply(this, arguments)
  };
},

/**
fork icon676
star icon0
watch icon2

+ 3 other calls in file

52
53
54
55
56
57
58
59
60
61
var tabPaneTabs = [{
  name: 'layers',
  label: _t('editor.tab-pane.layers.title-label'),
  selected: this.options.selectedTabItem === 'layers',
  createContentView: function () {
    var layersStackViewCollection = new Backbone.Collection([{
      createStackView: function (stackLayoutModel, opts) {
        return new ScrollView({
          createContentView: function () {
            return new LayersView({
fork icon676
star icon0
watch icon0

+ 3 other calls in file

57
58
59
60
61
62
63
64
65
66
var modals = new ModalsServiceModel();
var tableModel = new TableModel(tableData, { parse: true, configModel: configModel });
var editorModel = new EditorModel();
var Router = new Backbone.Router();
var visModel = new VisTableModel(visData, { configModel: configModel });
var layersCollection = new Backbone.Collection(layersData);
var layerDataModel = layersCollection.find(function (mdl) {
  var kind = mdl.get('kind');
  return layerTypesAndKinds.isKindDataLayer(kind);
});
fork icon676
star icon0
watch icon4

17
18
19
20
21
22
23
24
25
26
fetch: function(opts) {

  var query = this._generateQuery(opts.type, opts.orderBy, opts.page, opts.limit);
  opts = _.extend({ q: query }, { reset: opts.reset });

  Backbone.Collection.prototype.fetch.call(this, { data: opts });
},

_generateQuery: function(type, orderBy, page, limit) {
  var fields = [
fork icon676
star icon0
watch icon2

+ 3 other calls in file

1
2
3
4
5
6
7
8
9
10
var _ = require('underscore');

module.exports = Backbone.Collection.extend({
  constructor: function (models, options) {
    options = _.extend(options || {}, { silent: false });
    Backbone.Collection.prototype.constructor.call(this, models, options);
  },

  initialize: function (models, options) {
    this._disabledTabs = options.disabledTabs;
fork icon676
star icon0
watch icon3

+ 3 other calls in file

3
4
5
6
7
8
9
10
11
var Doc = require('../models/doc')
var rsSync = require('rs-adapter')
var lang = require('../translations')
const uuid = require('uuid/v4')

var Docs = Backbone.Collection.extend({
  model: Doc,

  sync: rsSync,
fork icon59
star icon347
watch icon18

3
4
5
6
7
8
9
10
11
12
 * A Backbone Collection designed to keep track of all notebooks, allowing
 * us to hit the network as infrequently as possible.
 *
 * @type {Function}
 */
var PersistenceItems = module.exports = Backbone.Collection.extend({
  model: require('../models/persistence-item')
});

/**
fork icon45
star icon153
watch icon471

0
1
2
3
4
5
6
7
8
9
"use strict";

var Backbone = require('backbone'),
    Blueprint = require('./blueprint');

var BlueprintCollection = Backbone.Collection.extend({
  model: Blueprint,
  url: '/blueprints',

  get: function(id_or_slug) {
fork icon37
star icon414
watch icon145

25
26
27
28
29
30
31
32
33
34
var endpoints = {
  stream: 'http://api.flickr.com/services/feeds/photos_public.gne',
  faves: 'http://api.flickr.com/services/feeds/photos_faves.gne'
};

var Photos = Backbone.Collection.extend({

  url: function() {
    var endpoint = endpoints[this.getAttribute('endpoint')];
    if (!endpoint) {
fork icon1
star icon0
watch icon2

39
40
41
42
43
44
45
46
47
48
49
    },
    idAttribute: 'name',
    url: '/test'
});


const todoItems = new Backbone.Collection({
    model: taskModel,
    comparator: 'id',
    url: '/test'

fork icon0
star icon0
watch icon0

155
156
157
158
159
160
161
162
163
164
  toggle: function() {
    this.set('pick', !this.get('pick'));
  }
});

var RebaseEntryCollection = Backbone.Collection.extend({
  model: RebaseEntry
});

var RebaseEntryView = Backbone.View.extend({
fork icon0
star icon0
watch icon533

92
93
94
95
96
97
98
99
100
101
var BarView = Mn.View.extend({
  template: '#bar-template'
});

var MyNextCollectionView = Mn.NextCollectionView.extend({
  collection: new Bb.Collection(),
  childView: function(item) {
    // Choose which view class to render,
    // depending on the properties of the item model
    if  (item.get('isFoo')) {
fork icon0
star icon0
watch icon2

228
229
230
231
232
233
234
235
236
237
var Mn = require('backbone.marionette');

var cv = new Mn.CollectionView({
  childView: SomeChildView,
  emptyView: SomeEmptyView,
  collection: new Bb.Collection([
    { value: 1 },
    { value: 2 },
    { value: 3 },
    { value: 4 }
fork icon0
star icon0
watch icon2

+ 5 other calls in file