How to use the Model function from backbone

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

4
5
6
7
8
9
10
11
12
13

var MediaController = wp.media.controller.State.extend({

        initialize: function(){

                this.props = new Backbone.Model({
                        currentShortcode: null,
                        action: 'select',
                        search: null,
                        insertCallback: this.insertCallback,
fork icon149
star icon670
watch icon60

34
35
36
37
38
39
40
41
42
43
    readonly index?: number;
    readonly onlyOne?: boolean;
}


const Instance = Backbone.Model.extend({

    initialize() {

        this.transId = 0;
fork icon52
star icon458
watch icon25

+ 3 other calls in file

14
15
16
17
18
19
20
21
22
23
const AnalyseTab = require('./ribbon/analysetab');
const Notifs = require('./ribbon/notifs');
const focusLoop = require('../common/focusloop');
const selectionLoop = require('../common/selectionloop');

const RibbonModel = Backbone.Model.extend({

    initialize(args) {
        this._modules = args.modules;
        this._settings = args.settings;
fork icon52
star icon457
watch icon25

4
5
6
7
8
9
10
11
12
13
    _ = require('underscore'),
    moment = require('moment'),
    utils = require('../utils'),
    markdown = require('markdown').markdown;

var Project = Backbone.Model.extend({
  urlRoot: '/projects',

  /**
   * Constructor. Looks for `blueprint` or `blueprint_name` in the object passed in.
fork icon37
star icon414
watch icon145

+ 5 other calls in file

2
3
4
5
6
7
8
9
10
11
var Backbone = require('backbone'),
    _ = require('underscore'),
    utils = require('../utils'),
    ProjectCollection = require('./project_collection');

var Blueprint = Backbone.Model.extend({
  /**
   * Constructor.
   * @param {object} args Arguments passed to the constructor
   **/
fork icon37
star icon414
watch icon145

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

var Backbone = require('backbone'),
    _ = require('underscore');

var Theme = Backbone.Model.extend({
   /**
   * Get the AJAX endpoint for this blueprint.
   * @returns {string}
   **/
fork icon37
star icon414
watch icon145

8
9
10
11
12
13
14
15
16
17
From the Backbone.js documentation:

> Brief aside on super: JavaScript does not provide a simple way to call super — the function of the same name defined higher on the prototype chain. If you override a core function like set, or save, and you want to invoke the parent object's implementation, you'll have to explicitly call it, along these lines:

> ```javascript
var Note = Backbone.Model.extend({
        set: function(attributes, options) {
                Backbone.Model.prototype.set.call(this, attributes, options);
                ...
        }
fork icon24
star icon209
watch icon11

+ 7 other calls in file

32
33
34
35
36
37
38
39
40
41

var BaseView = function(options) {
    this.viewId = makeId(options);
    this.refs = {};

    var Props = this.propsModel || Backbone.Model;
    this.props = new Props( _.omit(options, Config.ViewOptions) );

    this._bindChannels();
    Backbone.View.apply(this, arguments);
fork icon31
star icon202
watch icon46

3
4
5
6
7
8
9
10
11
12
/**
 * Model used for holding a notebooks meta data.
 *
 * @type {Function}
 */
var Meta = module.exports = Backbone.Model.extend();

/**
 * Reset a model by removing any unused attributes and updating everything else.
 *
fork icon45
star icon152
watch icon0

+ 3 other calls in file

73
74
75
76
77
78
79
80
81
82
        storage[method](this._persistenceKey(attr), attrs[attr]);
      }
    }
  }

  return Backbone.Model.prototype.set.apply(this, arguments);
};

/**
 * Override `clear` to also empty localStorage.
fork icon45
star icon152
watch icon472

+ 7 other calls in file

220
221
222
223
224
225
226
227
228
229

return Marionette.ItemView.extend({
        initialize: function(options) {
                var attrs = extractAttributes(options);

                this.model = new Backbone.Model(attrs);
        };
});

// bad (extractAttributes is an additional method on the view unnecessarily)
fork icon42
star icon156
watch icon52

15
16
17
18
19
20
21
22
23
24
  expect(this.policy.shouldEvictItem({ evictMe: true })).to.be.false;
});

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);
  });
fork icon10
star icon58
watch icon59

+ 3 other calls in file

173
174
175
176
177
178
179
180
181
182
if(this.properties.size){
    w = this.properties.size[0] || 0;
    h = this.properties.size[1] || 0;
}

this._constraintRelations = new backbone.Model({});
this._autolayout.width = autolayout.cv('width', w);
this._autolayout.height = autolayout.cv('height', h);
this._autolayout.top = autolayout.cv('top', 0);
this._autolayout.right = autolayout.cv('right', 0);
fork icon6
star icon35
watch icon14

9
10
11
12
13
14
15
16
17
18

var auth = require('../config');
var cookie = require('../cookie');
var templates = require('../../dist/templates');

module.exports = Backbone.Model.extend({
  initialize: function(attributes, options) {
    this.repos = new Repos([], { user: this });
    this.orgs = new Orgs([], { user: this });
  },
fork icon744
star icon0
watch icon12

19
20
21
22
23
24
25
26
27
28

*/

const CURRENT_VERSION = 1;

const KeeVaultEmbeddedConfigModel = Backbone.Model.extend({

    defaults: function() {
        return {
            version: CURRENT_VERSION,
fork icon7
star icon57
watch icon7

67
68
69
70
71
72
73
74
75
76
77
78
79
Automation.EventAggregator = function () {


  var EA = function(){};


  // Copy the *extend* function used by Backbone's classes
  EA.extend = Backbone.Model.extend;


  // Copy the basic Backbone.Events on to the event aggregator
  _.extend(EA.prototype, Backbone.Events);

fork icon23
star icon17
watch icon4

32
33
34
35
36
37
38
39
40
41
42
43


/**
 * MODELS
 **/


app.Container = Backbone.Model.extend({
  url: function() {
    return '/';
  },
  wsUrl: function() {
fork icon7
star icon1
watch icon3

31
32
33
34
35
36
37
38
39
40
41
    },
    idAttribute: 'id',
    url: '/test'
});


const userModel = Backbone.Model.extend({
    defaults: {
        name: ''
    },
    idAttribute: 'name',
fork icon0
star icon0
watch icon0

131
132
133
134
135
136
137
138
139
140
this.gotoRoute("/user/create", {
  trigger: true
});
// RootView.getInstance().setView(new LandingPageView());
// RootView.getInstance().setView(new CreateUserFormView({
//   model : new Backbone.Model({
//     // zinvite: zinvite,
//     create: true
//   })
// }));
fork icon0
star icon0
watch icon1

+ 2 other calls in file