Models in the Backbone.js library.
Questions tagged [backbone-model]
325 questions
2
votes
1 answer
backbone.js error when using fetch but not $.ajax()
I am having some trouble fetching a collection. I'm using the console's network inspector to see if I can figure out what's wrong and the only thing I see is the format of the Request Payload.
When making a .fetch() the Request Payload is being sent…

Charles
- 309
- 1
- 16
1
vote
1 answer
Wait for several backbone models to save using $.when.apply
I'm trying to save several backbone models (not in a collection) and execute code after they all get saved.
This is my code simplified:
var requestsArray = modelsArray.map(function(model) {
return model.save();
});
$.when.apply(undefined,…

pesho hristov
- 1,946
- 1
- 25
- 43
1
vote
0 answers
Backbone destroy method is triggering post call instead of delete when type: "DELETE", is not passed
var asset = Backbone.Model.extend({
urlRoot: 'https://www.example.com/asset/',
idAttribute: "assetId",
});
var k = new asset({"assetId":11174355100070});
k.destroy({
…

VSP
- 11
- 1
1
vote
1 answer
Clear all attributes except one on a Backbone Model
I have a model that has more attributes than the default attributes. I need to clear all attributes when guest changes and set back to defaults so I don't carry unnecessary attributes.
Clearing all attributes and setting the defaults back causes an…

user2326737
- 211
- 1
- 4
- 16
1
vote
1 answer
this.model.on change event not firing
The "change" event is not firing in the following code.
var PageView = Backbone.View.extend({
el: $("body"),
initialize: function(){
this.model.on("change:loading", this.loader, this);
},
loader: function(){
…

aleXela
- 1,270
- 2
- 21
- 34
1
vote
1 answer
Bind a Backbone Model attribute to a TinyMCE text
I'm making a form with rich text in it. I have TinyMCE for that, Backbone controls the logic and underscore is used for templating.
I can't find if there's a way to bind a Backbone model to the TinyMCE value?
Something like:
var backboneModel = new…

mindz
- 87
- 1
- 8
1
vote
3 answers
When to destroy my model in case of multiple views depending on it
I have a case where I am creating multiple views for a single model. When I close a view, I am removing the model from the collection.
But in case of multiple views, there are other views that depend on the model.
So, how can I know when there are…

Dharini S
- 1,103
- 2
- 8
- 6
1
vote
1 answer
Backbone Collection model duplicate itself
So, I have a table view (parent) and row view (child).
I add every row with this code
addOne: function (model, base) {
var view = new App.Views.file_manager_item({model: model});
base.append(view.render());
},
renderList: function () {
…

Vasiliy Rusin
- 955
- 6
- 13
1
vote
3 answers
What is the type of 'child'?
I know type of Object and Array. I know how to use and how to create Object and Array but I don't know what's the type of child in JavaScript and how to create type of child?
This is a chrome console screenshot.

jasondayee
- 549
- 4
- 11
1
vote
1 answer
How to force a POST request when saving a model?
I need to make a POST to a server-side API. I must send an id key into the request body to the server.
I use a Backbone model. But when I do:
myModel.set("id", somevalue)
myModel.save()
The network request that is fired is : URL/someValue …

Doctor
- 7,115
- 4
- 37
- 55
1
vote
1 answer
How to destroy the created objects in BackboneFactory and where are they stored?
This is the source for BackboneFactory, a Backbone equivalent of FactoryGirl:
// Backbone Factory JS
// https://github.com/SupportBee/Backbone-Factory
(function(){
window.BackboneFactory = {
factories: {},
sequences: {},
define:…

Jwan622
- 11,015
- 21
- 88
- 181
1
vote
1 answer
Relation between models in backbone.js
I'm looking for the correct backbone structure to achieve the following:
Two server APIs:
GET api/event/4 : returns the event object with id 4.
GET api/event/4/registrations : returns the list of registration objects belonging to event with id 4
I…

Quentin Gillet
- 69
- 1
- 7
1
vote
0 answers
Backbone.js - Creating models and collections for entities having two-way relationships
I am trying to build a simple student listing app using Backbone.js which will allow users to view:
All the students of a university.
All the courses available.
All the students enrolled for a particular course.
All the courses in which a…

sudbesus
- 11
- 2
1
vote
1 answer
handling null model attributes in a backbone / underscore template
I have a model whose data is displayed in a backbone view/underscore template.
I setup the template in my view like this:
return Backbone.View.extend({
className: 'officeAlerts',
template: _.template(OfficeAlertsTmpl, null, {…

SkyeBoniwell
- 6,345
- 12
- 81
- 185
1
vote
1 answer
Get the name/type of a backbone model
I have a somewhat generic view that can except 6 different types of models.
I create the view and pass in the model like this:
var view = new MyView({
model: myModelType //can be 1 of 6 different model types
});
In the view, I…

SkyeBoniwell
- 6,345
- 12
- 81
- 185