Models in the Backbone.js library.
Questions tagged [backbone-model]
325 questions
119
votes
12 answers
Nested Models in Backbone.js, how to approach
I've got the following JSON provided from a server. With this, I want to create a model with a nested model. I am unsure of which is the way to achieve this.
//json
[{
name : "example",
layout : {
x : 100,
y : 100,
…

Ross
- 14,266
- 12
- 60
- 91
107
votes
9 answers
Backbone.js get and set nested object attribute
I have a simple question about Backbone.js' get and set functions.
1) With the code below, how can I 'get' or 'set' obj1.myAttribute1 directly?
Another question:
2) In the Model, aside from the defaults object, where can/should I declare my model's…

fortuneRice
- 4,214
- 11
- 43
- 58
60
votes
7 answers
Easiest way to reset Backbone's model to initial defaults?
My models already have a defaults hash. When parts of the view/page are reset, I wish to reset the models back to their original defaults.
Currently, I explicitly set each attribute to its default value. Is there anything built in or a…

PhD
- 11,202
- 14
- 64
- 112
26
votes
2 answers
In Backbone.js, why do silent changes trigger change events eventually?
When I pass {"silent":true} while setting an attribute in a Backbone model, why doesn't that just suppress the change:attribute event? What is the advantage of firing that event the next time an attribute is changed?
Update
Backbone 0.9.10 changed…

stinkycheeseman
- 43,437
- 7
- 30
- 49
23
votes
2 answers
Correct way of binding multiple attribute changes to a Backbone.js model
I have the following code, where I bind a change to a single attribute "attribute_1".
var Mine = Backbone.Model.extend({
initialize: function() {
this.bind("change:attribute_1", function() {
console.log('changed!');
});
}
});
How…

ericbae
- 9,604
- 25
- 75
- 108
15
votes
2 answers
Updating changed attributes with backbone.js
So I'm setting a model with updated attributes.
Then in my view I'm listening for a change event for this model.
When that fires I think I should use model.changedAttributes? Do I pass it a callback?
It should return a hash of all the attributes…

fancy
- 48,619
- 62
- 153
- 231
12
votes
4 answers
Backbone.js - model.save() not firing a PUT request
I have a basic application using Backbone.js that is not making PUT calls (updating model). From the front-end, I calling a models save function doesn't make a PUT call; however, if I replace it with destroy, it does make a DELETE call to the…

Theo Alvarez
- 123
- 1
- 1
- 5
12
votes
2 answers
Backbone.js - How to save model by form and post to server
I'm n00b in BackboneJS/RequireJS and I'm developing an web app that use a RESTful API.
So I've a model like this:
models/pet.js
define([
'backbone'
], function(Backbone){
var PetModel = Backbone.Model.extend({
urlRoot:…

Carlos Azaustre
- 395
- 2
- 6
- 15
12
votes
1 answer
{silent:true} in Backbone 1.0 version
I was updating my backbone version from 0.9.2 to 1.0 yet I've encountered a problem.
The model is not updating properly. It has delays in it. previously my code below works perfectly:
this.model({ attrib: true},{silent:true});
But after updating I…

n0minal
- 3,195
- 9
- 46
- 71
11
votes
4 answers
How to know when a Backbone model.fetch() completes?
I bind on the change event of my backbone models like this.
this.model.on( "change", this.render, this );
Sometimes I want to fetch the latest version of the model and forcibly render the view. So I do this
this.model.fetch();
Unfortunately…

user1031947
- 6,294
- 16
- 55
- 88
11
votes
3 answers
Completely remove attribute from Backbone.js model
I am trying to totally remove an attribute from a backbone model. The model is being sent to an API that isn't very flexible, and it will break if I send additional attributes over the ones I'm supposed to send, so I need to remove an attribute so…

FrizbeeFanatic14
- 339
- 3
- 5
- 13
11
votes
2 answers
How do I tell backbone that the model is not new
I have an object that's also saved in the server and I'm creating a Backbone model from that object.
But when I save the model, it's doing a PUT request, which is not what I want. How to tell Backbone that the data is already in the server without…

archmage
- 1,101
- 10
- 10
10
votes
1 answer
Error: a url property or function must be specified
These are my initial days of working on BackBone.js. I am actually stuck with the router part as i am getting an error in the console "Error: a url property or function must be specified". This is my scenario; I have a click function which…

Dipin Krishnan
- 1,260
- 3
- 21
- 41
9
votes
1 answer
Backbone - not parse each model in collection after fetch
How to prevent parse function for model in collection fetching?
$(function() {
var Task = Backbone.Model.extend({
url : function() {
return this.urlRoot + this.id;
},
urlRoot:…

Gabriel
- 439
- 2
- 4
- 13
7
votes
2 answers
Backbone Model : Ajax request in parse override
I have a scenario where a fetch() call of a model will return data from which a property will need be passed to another API and return type from that API will be the actually required data.
var Issue = Backbone.Model.extend({
urlRoot:…

lbrahim
- 3,710
- 12
- 57
- 95