Moved to BackboneJS and JQuery Templates
akshay.cc
akshay.cc
akshayr mentions that in the context of an event handler in a View, "this" is bound to the instance of the view -- which differs from jQuery, where "this" is bound to the element that the event originated from. This is by design: it's awfully nice if methods on a View maintain their notion of "this", regardless of if they're called directly, or triggered by a DOM event. If you want to know which element was clicked, that's what "event.target" is good for, where "event" is the object that jQuery passes as the first argument to all DOM events. Here's an example that makes use of both "this", and the specific element:
var NoteList = Backbone.View.extend({
events: {
"click .note .title": "openNote"
},
openNote: function(e) {
var el = $(e.target);
var note = this.notes.get(el.attr('data-id'));
note.open();
}
...
});
The other issue raised is the lack of JSONP support in the default implementation of Backbone.sync. It would be great to make this a configurable option, without having to drop down into jQuery for simple fetches, as akshayr did. Hopefully this will be a part of the next release.http://documentcloud.github.com/backbone/test/test.html
But I'm afraid to say that we don't actually test the JavaScript in the DocumentCloud workspace very much. It's something that I'd love to do more of, but almost all of the bugs that actually occur in production aren't things that unit tests would catch -- unexpected responses from remote Ajax calls, CSS glitches in IE, etc.
That said, having nice standalone models is a great start for testable code.
I'm currently using knockout.js with jquery templates to generate a 'feed' component that has unique content for each user. The content also changes very rapidly so there is little point in a search engine trying to index any single version of the page. I was quite hesitant to go with the JavaScript templating approach at first (ie would normally have gone with generating the content on the server), but it has made quite a few things significantly easier.
As long as you're mindful that search engines won't be able to index any javascript-generated content, you should be able to consider the use of all these new client-side templating tools.
The addresses of the MPs of Karnataka state, many of whom reside in Bengaluru.
Also, using javascript everywhere breaks linkability, as evidenced by my inability to link to the exact page in question :)
2> Linkability and searchability (search engine bots and SEO) are certainly a problem in these kind of apps. In this particular case, I've been thinking about providing a way for other websites to embed and link to mp information.