Models in the Backbone.js library.
Questions tagged [backbone-model]
325 questions
1
vote
0 answers
Run code after Backbone model is fetched or instantiated with model data
What's a clean way to run some code during initialize() if a Model is constructed with all its data, but otherwise run that code only after a fetch? The best I have is something like the following, but I'm hoping there's a more streamlined way of…

Cameron
- 2,276
- 2
- 15
- 12
1
vote
3 answers
Filter a backbone collection based on multiple model attributes
I am wanting to filter a backbone collection so returned to me are are only models that match or are close too some search parameters,
My models structure looks like this,
{
email: "name@domain.com",
first_name: "Name",
surname:…

Cycs
- 229
- 1
- 5
- 15
1
vote
2 answers
Backbone JS: Assign a model attribute in fetch call
Sorry, if this is basic but I'm a total starter with Backbone.js and I can't work out how to simply assign an attribute (data) with data obtained from fetch. I believe it's to do with binding (this), but I can't figure it out. Here's my code:
var…

Adam Moss
- 5,582
- 13
- 46
- 64
1
vote
2 answers
My Backbone Model's validate method called on model.fetch, but not on collection.fetch
EDIT tl;dr: I would like to only fetch models and add them to the collection that meet some validation criteria. I am able to use the model.validate() method if I am fetching only a single model, but when using collection.fetch(), model.validate()…

elsherbini
- 1,596
- 13
- 23
1
vote
1 answer
Backbone model structure gets changed when returning them from web worker
I am trying to reset a backbone collection with an array of models. It gets reset but the model structure is changed (nested one level).
Here is a detailed explanation:
Model
var SeatModel = Backbone.Model.extend({
defaults:{
},
…

Himanshu Arora
- 2,368
- 3
- 22
- 33
1
vote
1 answer
Issue about backbone and collections and added mechanism
I develop a web application - it's a some html block which must rerender when user pres next or prev button - it's a carousel.
I have an array of 5 elements (videos) and user view it one by one pressing next or prev button.
When application is init…

user3193094
- 25
- 5
1
vote
1 answer
Backbone PUT is sending data www-form-urlencoded instead of application/json
I'm pretty new to backbone and how it works and inherited a bunch of code but I can't solve this at all:
I have a user model:
var User = Backbone.Model.extend({
idAttribute: 'username',
defaults: {
username: "",
email: "",
…

bugg
- 61
- 6
1
vote
1 answer
Backbone reformat model
Hello I have a model in backbone that looks like this,
Project {cid: "c2", attributes: Object, _changing: false, _previousAttributes: Object, changed: Object…}
_changing: false
_pending: false
_previousAttributes: Object
…

Udders
- 6,914
- 24
- 102
- 194
1
vote
2 answers
What is the best practice for nested models in Backbone?
I have a Collection "Map" and two models "Zone" and "Section".
Zone attributes:
zone_title: "New zone"
width: 0
height: 0
order: 0
sections: []
Section attributes:
section_title: "New section"
content: "Some texts"
…

kLezer
- 211
- 1
- 7
1
vote
1 answer
Passing custom headers with Backbone.js collection.sync
Without having to implement a custom collection.sync, is it possible to send custom headers to the server when Backbone.js calls its sync method?
That is, I want to pass a customer header to the server when I perform an operation, like…

Swisher Sweet
- 769
- 11
- 33
1
vote
2 answers
Backbone.js design pattern for JSON data
I've got a question about best practice when designing JSON file which will be displayed by Backbone.js. I know that Backbone is completly agnostic in this topic, but maybe someone will give me good advice in this certain situation.
In the end, I…

user1854236
- 446
- 1
- 5
- 16
1
vote
1 answer
clone backbone model attributes
I have one backbone model containing 10 attributes, Now I want 5 attributes ( out of this 10 attributes ), to be copy/clone in my another newly created model. I can do this thing with getting/setting individually, but I want to know, is there any…

Manish Sapkal
- 5,591
- 8
- 45
- 74
1
vote
1 answer
User "GET" request in Backbone
I'm trying to use the GET method to send and retrieve information from the server but I seem to be having some trouble with the formatting the data for transport.
Does backbone serialize the data into url parameters when using .save() .fetch() or…

Kendall
- 5,065
- 10
- 45
- 70
1
vote
1 answer
Using multiple models and collections in Marionette/Backbone view
I'm not sure what the right approach here is. I am setting up a simple form. I need a couple of standard HTML input fields and a couple of select inputs. The data is coming from a couple of different sources and I would like to present the models…

Wittner
- 583
- 5
- 21
1
vote
1 answer
Change listener on collection (obviously listening models change)
I have a tabular data view with ability to sort on each individual column. As data being huge, I prefer to show few rows in the page and load rows on demand. So wheneever user sorts a column in page, a new request is made to server and new data rows…

ykjs121
- 385
- 1
- 2
- 16