Questions tagged [backbone-model]

Models in the Backbone.js library.

Docs

325 questions
1
vote
1 answer

Rendering backbone submodel in handlebars template

I have model and submodel: var Field = Backbone.Model.extend(); var MetaField = Backbone.Model.extend(); var metaField = new MetaField({ title: 'width' }); var field = new Field({ meta: metaField, value: 5}); and I want to render this model via…
kharandziuk
  • 12,020
  • 17
  • 63
  • 121
1
vote
1 answer

Backbone Collection is Half-Sorted When Comparator is Used

I am using backbone's collection model to display a sorted list of strings on a backbone view. Here is the model and the comparator: var MenuItems = Backbone.Collection.extend({ comparator: function (a, b) { if (a.get('name') < b.get('name'))…
Branka
  • 469
  • 1
  • 5
  • 11
1
vote
1 answer

Backbone targetModel = undefined

I am running into this issue with backbone where the model seems to be undefined to backbone, though all scripts are loaded. (I am using require to load backbone and other javascript files). So whenever I do a collection.fetch I get this error in…
BonifatiusK
  • 2,281
  • 5
  • 29
  • 43
1
vote
1 answer

How to mock an error callback for a BackboneJS model (in destroy)?

Given the following BackboneJS 1.1.0 model / MarionetteJS 1.0.4 module: MyApp.module('Product', function(Product, App, Backbone, Marionette, $, _) { Product.Model = Backbone.Model.extend({ destroy: function() { …
JJD
  • 50,076
  • 60
  • 203
  • 339
1
vote
1 answer

Validation in Backbone Models

I am following these https://tutsplus.com/course/connected-to-the-backbone/ lectures to learn backbone and it came into my knowlege that validate() function (if exists) is called whenever we set the value of any variable inside that model. I have…
Kamran Ahmed
  • 11,809
  • 23
  • 69
  • 101
1
vote
1 answer

Backbone collection's models disapear after parse

I have this model and a collection for it: app.models.Result= Backbone.Model.extend({ idAttribute: 'uid', initialize: function () { this.set('name', this.get('name').replace(' ', '').substring(0, 20)); …
totymedli
  • 29,531
  • 22
  • 131
  • 165
1
vote
1 answer

Backbone.js collection not fetching successful by id

So i have mongodb collection of attendees _id event_id name profile_picture user_id I am routing two GET attendees collection app.get('/attendee', event.eventAttendee); app.get('/attendee/:event_id',…
1
vote
0 answers

model saving but success and error callbacks not executing

I save a backbone model, the save is successful. However the success or the error function dont seem to be getting called. Here is what I have tried : that.model.save(null,{ success:function(model, response){ console.log("save…
user2620049
1
vote
1 answer

How do i stop a single model adding his id to url in Backbone?

i have a problem with backbone.js. I'm creating a frontend for an existing api, for me unaccessable. The problem is that when I try to add a new model to a collection, i can see in my firebug that every time backbone tries to create the model it…
1
vote
1 answer

Re-insert model into a sorted collection's view after editing

I'm comfortable with the comparator function in Backbone.Collection and I'm also comfortable with the idea of sorting a collection and then redrawing the whole thing from a view. However, I'm not looking for that here. I've got a collection that has…
1
vote
1 answer

Extending Backbone Collections to add logic, with custom methods, is a bad practice?

Usually I find my self needing to write an object with a specific functionality that it is a set of models. Finally I extend a collection and add more functions that works with its model. I think is better show you an example: My app has a set of…
ccsakuweb
  • 789
  • 5
  • 17
1
vote
3 answers

BackboneJS: iterate on model attribute and change value

I want to make a function with functionality like toJSON()'s functionality which returns and edits model. My question is how to iterate on model's attribute and edit the specific value of the attribute you selected. If have a model e.g: Item =…
jrsalunga
  • 409
  • 2
  • 8
  • 20
1
vote
1 answer

Retrieve a Backbone Model from a Clicked Subview and Create a New View with it

Say I've built a MainView (a list) that has populates a collection with four Backbone models. Then, for each model in the collection, I render a SubView (a list item) based off of the data in each model. Ignoring whether or not this nested view…
1
vote
1 answer

Backbone View says model is undefined?

i'm trying to get my feet wet with Backbone, but I can't figure out what's wrong here: var ToDoApp = { model: Backbone.Model.extend({ default:function(){ return { task: '', …
1
vote
2 answers

Backbone - Binding form submission back to model with nested json data

I've been racking my brain over this issue for a few days and cant come up with a decent solution. I have the following model { "id": "123", "key1": "foo", "key2": "bar", "metadata": { "height": 1, "width": 1 }, "userPrefs": [ …
redeye
  • 173
  • 8