logo
down
shadow

Different model types in one collection Backbone


Different model types in one collection Backbone

By : Wade
Date : November 22 2020, 10:31 AM
may help you . So the solution was a mix of using model function and return.
Here goes the explanation:
code :
parse: function (resp, options) {
    return resp;
}
{{1:data},{2:data}}
model: function (attr, options) {
    if(attr.hasOwnProperty('prop')){
        return new PropModel(attr,options);
    }
    else if (attr.hasOwnProperty('anotherProp')){
        return new AnotherPropModel(attr,options);
    }
},

parse: function (resp, options) {
    var response = [];
    _.each(resp, _.bind(function (r) {
        response.push(r);
    },this));
    return response;
}


Share : facebook icon twitter icon
Extending Backbone.Collection and Backbone.Model to create new Collection/Model types

Extending Backbone.Collection and Backbone.Model to create new Collection/Model types


By : Arthur Mattos
Date : March 29 2020, 07:55 AM
hop of those help? I have been trying to create my own base Models and Collections for extending in my apps. By this I mean that instead of calling:
code :
App.Model = Backbone.Model.extend({
  //do whatever you want to be present in all of your models
});
var MyModel = App.Model.extend({
  // Do whatever you want to do for this particular type of model
});
Backbone.Model save -- returned model's child is array not Backbone.Collection.

Backbone.Model save -- returned model's child is array not Backbone.Collection.


By : Burce.Zhang
Date : March 29 2020, 07:55 AM
wish of those help It kind of depends on what your server is expecting and what it responds with. Backbone does not know that the attribute items is a Backbone Collection and what to do with it. Something like this might work, depending on your server.
code :
 var Playlist = Backbone.Model.extend({
    defaults: function() {
        return {
            id: null,
            items: new PlaylistItems()
        };
    },
    toJSON: function(){
        // return the json your server is expecting.
        var json = Backbone.Model.prototype.toJSON.call(this);
        json.items = this.get('items').toJSON();
        return json;
    },
    parse: function(data){
        // data comes from your server response
        // so here you need to call something like:
        this.get('items').reset(data.items);
        // then remove items from data: 
        delete data.items;
        return data;
    }

});
How to create a collection with several model types in backbone.js?

How to create a collection with several model types in backbone.js?


By : Paul Elson
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further A nice way of handling this is to redefined the model attribute, which tell the collection how to add a new model to the collection, as explained in this POST : A Backbone.js Collection of multiple Model subclasses (thanks @rulfzid, who answered my question :))
In your case, you should be able to define the model attributes like this :
Destroy event not propagating from Backbone model to Backbone collection

Destroy event not propagating from Backbone model to Backbone collection


By : TItus Gabriel Mihu
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I think you are not instantiating the collection at all. Cant make out that from the code at least. If you are just creating a model instance but not adding it to any collection, this.model.trigger("destroy"); will do nothing.
Change event does not propagate from Backbone Collection to Backbone Model

Change event does not propagate from Backbone Collection to Backbone Model


By : qwertyqwer qwertyqwe
Date : March 29 2020, 07:55 AM
With these it helps Provided you're not referencing a collection that the model's part of (which would create circular logic), you should be able to bind it explicitly:
Related Posts Related Posts :
  • javascript - explanation request of a behaviour
  • Converting String into date format in JS
  • Choose element Angular
  • Display background grid by using image with CSS
  • Call function from another Controller in another file AngularJS
  • How to change texture in Gera library?
  • When trying to use windows.location.href , the values of $_POST[''] is lost
  • jQuery click action on appended item
  • NodeJS & Socket.IO: Emit a request event and get the response, when/where should I bind the listener?
  • 4-digit form on bootstrap modal
  • Prevent characters like quotation marks from input
  • Sign in option creation using jsp and oracle database
  • use socket.io in my controller with yeoman
  • What happens under the hood to prevent calling a bound method changing the this object?
  • issue with jquery .append function
  • Is it possible to EventHandle every GET request a page makes via Javascript?
  • How to select class with ng-if
  • Cannot communicate with websocket. Autobahn: received HELLO message, and session is not yet established
  • Socket.io - Cannot connect to client
  • Load Accordian Panel on click rather than page load
  • How to register async middleware module within express.js app?
  • JS / Cannot read property 'push' of undefined
  • how to make jquery plugin?
  • MATH reverting rotated coordinates
  • Add an expandable text box to every post
  • What was the rationale behind having the receiver in functions default to the global object?
  • JavaScript chaining many function
  • while loop over takes the each method
  • What are the difference between $(document).bind('ready', function) and $(document).ready(function() {})
  • cut the string in javascript
  • Tool tip not working on text area bootstrap
  • AngularJS: how to activate first non zero item in ngRepeat?
  • Pattern for "column total" of an array of arrays
  • Any selector using * failed in my case
  • Uncaught ReferenceError: app is not defined in Angularjs
  • Unit testing controller which has a $state.go method in controller
  • Use of Meteor-ui-progress-circle (accessing to Template variables created in the HTML)
  • JavaScript: Google maps mapOptions?
  • How do I track Universal Analytics events through Google Tag Manager?
  • Firefox Scrolling Bug When Changing :after Contents
  • Drop down list does not work
  • Display month and year specific datepicker in jquery
  • How to show BAr graph rather than line graph in High Stoch Chart
  • Accessing Angular $Scope in web workers
  • How to convert JavaScript(UnityScript) to C# and implement a low pass filter?
  • Need a logic to implement select button value via onchange event
  • redirect in codeigniter using ajax function
  • How to populate this form data and post it with jquery
  • Retrive value from array id in js function
  • angularjs $index when ng-hide with ng-repeat
  • ExtJS TaskRunner
  • Progress bar not hiding after fetching values via AJAX in JavaScript
  • Pop up window code fails
  • how to make dynamic javascript array with key and value group
  • Implement Facebook API login with reactjs
  • What is the meaning of sign ':' in javascript
  • Change all id's in HTMLDivElement using jQuery
  • load multiple pages from different domain in different divs using javascript
  • Could Not Resolve Host github.com
  • jQuery "Chosen" on-filter event?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org