Tag: backbone.js

How to generate seperate RESTful urls for edit and update in Backbone js model?

I’m following Jame Yu’s Backbone tutorial here to create my own app. Below is my model. I wonder if there’s a way to generate separate urls for edit and update (RESTful) instead of just 1 as in the tutorial. I use Rails on the back end. Thanks. var BusinessCard = Backbone.Model.extend({ url : function() { […]

backbone.js parse 1 element (the Id)

For a id on a model in backbone, its just id and all lower cased. What if my Id on the server is called UserId. In the parse method for backbone, how do I change UserId to id and use the same names for all other properties? For eg. window.User = Backbone.Model.extend({ defaults: { UserId: […]

Javascript: is there a better way to execute a function after x amount of async database/ajax calls

using Backbone.js we have an application, in which on a certain occasion we need to send an ajax post to a clients webservice. however, the content to be posted, is dynamic, and is decided by a certain array. for each item in the array we need to go fetch a piece of data. after assembling […]

Backbone.js slash after hash in fallback – history pushState

I’m using Backbone.js’s routing. It generate urls for browsers like this: http://my-app.com/help For Internet Explorers (except IE10) and old non-HTML5 browsers: http://my-app.com/#help How to configure Backbone.js to generate fallback urls with additional slash, like this?: http://my-app.com/#/help

Backbone.js nested object structure

I am working on a project where we have data models that look basically like this… var library = { location: ‘Somewhere’ books: [ { name: ‘Good Book’, publisher: ‘Great publisher’ authors: [ { name: ‘Joe Schmoe’, age: ’65’ }, { name: ‘Robert Smith’, age: ’47’ } } } I am trying to figure out […]

Automatic _.bindAll() in backbone.js

Is there a way to automatically do an _.bindAll for a backbone.js object? I was talking to someone a while ago and they said that there was, but I have no idea where to start looking. Example: var TheView = Backbone.View.extend({ initialize: function() { // HOW CAN I AVOID HAVING TO DO THIS?—-> _.bindAll(this,’render’,’on_element_01_click’, ‘on_element_02_click’); […]

Backbone: No data added to model on fetch()

I have problems when i try to fetch data to my Backbone model from the server. You get a response in JSON from from the server which I think looks to be right formatted. Can you see anything wrong with it? It looks like: [{“id”:”1″,”name”:”Fawad Hassan”,”email”:”fawad@test.com”},{“id”:”2″,”name”:”Bill Gates”,”email”:”bill@test.com”},{“id”:”3″,”name”:”Steve Jobs”,”email”:”steve@test.com”},{“id”:”4″,”name”:”Naveed Ahmad”,”email”:”naveed@test.com”},{“id”:”5″,”name”:”Mr Zee”,”email”:”zee@test.com”}] My code for the Backbone […]

How can I tell if a model has not been changed in Backbone.js?

This may be a result of misuse of the component, though I don’t think so. I have an issue where a View updates a model in Backbone JS and calls the model’s Set method so that it may verify it’s input. In theory there are two results to such an action: Error and Change. Both […]

Backbone.js: How do you call a View's “method” from outside the View's scope (e.g: inside a model's validation handler)

Basically, I’m trying to do something like this: Person = Backbone.Model.extend({ validate: { … }, initialize: function(){ this.bind(‘error’, ?……?); <== what do I put? }, // I DON’T WANT TO CALL THIS ONE handleError: function(){ } }); ViewOne = Backbone.View.extend({ //I WANT TO CALL THIS ONE: handleError: function(model, error){ //display inside segmented view using jQuery […]

Backbone Model Fetch refresh event not firing

I hope i can abstract all the relevant parts. My question is why the render method isn’t executing when i fetch my model from the server. Model var Document = Backbone.Model.extend({ urlRoot: “/dms/reconcile/GetDocumentByDocumentId/” }); View window.DocumentView = Backbone.View.extend({ el: $(“#reconcile_document”), initialize: function () { this.model.bind(‘refresh’, this.render) //also tried reset }, render: function () { alert(“Do […]