How to use the Collection function from backbone
Find comprehensive JavaScript backbone.Collection code examples handpicked from public code repositorys.
GitHub: CartoDB/carto.js
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);
272
419
115
+ 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 () {
10
58
59
+ 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'
7
80
11
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) }; }, /**
676
0
2
+ 3 other calls in file
GitHub: toHero/cartodb
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({
676
0
0
+ 3 other calls in file
GitHub: foodora/cartodb
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); });
676
0
4
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 = [
676
0
2
+ 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;
676
0
3
+ 3 other calls in file
GitHub: litewrite/litewrite
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,
59
347
18
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') }); /**
45
153
471
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) {
37
414
145
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) {
1
0
2
GitHub: sofiafaddi/REACTJS
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'
0
0
0
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({
0
0
533
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')) {
0
0
2
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 }
0
0
2
+ 5 other calls in file
backbone.View is the most popular function in backbone (151 examples)