Tag: backbone.js

Backbone.js – Todo Collection – What exactly is happening in this return statement?

I’m looking back at the Backbone todo list and have a question about the collection. Here is the code: window.TodoList = Bacbone.Collection.extend({ model: Todo, localStorage: new Store(“todos”), done: function() { return this.filter(function(todo){return todo.get(“done”)}) }, remaining: function() { return this.without.apply(this, this.done()); } }) I understand everything that is going on here, except for the ‘remaining’ function. […]

Backbone render return this

I’m trying to figure out some of the ‘patterns’ to set up a Backbone-project. In the examples below, in the ‘render’-function, the author returns an instance of ‘this’. Why is this? Is it specific for the example, or something common for Backbone? I don’t see why one should return ‘this’ in the ‘render’-function. The examples […]

loops in underscore js template

Ok guys so I have this array of key pair values which I’m using as my model: var acs = [{‘label’:’input box’},{‘label’:’text area’}]; the rest of the code goes as follows var Action = Backbone.Model.extend({}); var action = new Action(acs); var ActionView = Backbone.View.extend({ tagName:”li”, template: _.template($(‘#actions-template’).html()), events:{ “click”:”makeInput” }, render:function(){ $(this.el).html(this.template(this.model.toJSON())); $(“.hero-unit>ul”).append(this.el); return this; […]

Overriding fetch() method in backbone model

I would like to override the default fetch() method in a Backbone model, thus calling it only when needed. Something like this: Account.Check = Backbone.Model.extend({ model : Account.Item, url : Settings.Url.checkAccount, fetch : function(options) { if (someCondition()) { // do some stuff } else { super.fetch(options); } } }); My question is how to provide […]

Using Jade templates in Backbone.js

I love the HAML-like syntax of Jade’s templating engine in Node.js, and I would love to use it client-side within Backbone.js. I’ve seen Backbone commonly using Underscore.js templating in the following style. /* Tunes.js */ window.AlbumView = Backbone.View.extend({ initialize: function() { this.template = _.template($(‘#album-template’).html()); }, // … }); /* Index.html */ <script type=”text/template” id=”album-template”> <span […]

django and backbone.js questions

I’m looking at making backbone.js (plus jQuery) work with my django app, but I have some questions. I’ve never used a restful setup before, so I have very little knowledge of the “proper” way to use REST. Backbone uses REST architecture, but django doesn’t support this by default. It looks like tastypie or piston are […]

How can I pass properties into a Backbone.Model which I do not wish to be treated as attributes?

I have a Backbone.Model named Company. My Company model has an Employees Backbone.Collection containing Employee models. When I instantiate my Employee models to populate the Employees collection I wish for them to have a reference to the Company they belong to. But when I pass Company in it becomes one of the attributes of Employee. […]

Browserify require returns an empty object

I have this code which, for reasons I can’t understand, produces an empty object when using require(). My file structure is like this: src |__ public |__ javascript |__ collections | categories.js | listings.js <– Always an empty object |__ models | category.js | employer.js | listing.js | location.js | routing | templates | tests […]

Backbone.js – how to handle “login”?

Hi I’m trying to wrap my head around backbone.js for some days now but since this is my first MVC Framework, it’s pretty hard. I can easily get my Collections to work, fetching data from the server etc, but it all depends on first “logging” in per API-Key. I just don’t know how to model […]

Override Backbone.sync() at Model level to send extra params?

To be quite honest I’m stuck trying to override Backbone’s sync() method for a Model, I have the signature for the function in place, and it gets triggered correctly, but I don’t know what to put in the function body in order for it to make a default call to DELETE but with extra arguments. […]