Skip to content

Instantly share code, notes, and snippets.

@nhunzaker
Last active November 5, 2017 00:07
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nhunzaker/9676031 to your computer and use it in GitHub Desktop.
Save nhunzaker/9676031 to your computer and use it in GitHub Desktop.
var _ = require('underscore');
var Backbone = require('backbone');
var cheerio = require('cheerio');
var request = require('request');
Backbone.ajax = function(options) {
options.json = true;
return request(options, function(error, result) {
if (error) {
if (_.has(options, 'failure')) options.failure(error);
} else {
(if (_.has(options, 'success')) options.success(result.body);
}
});
};
Backbone.View.prototype.setElement = function($cheerio) {
this.$el = $cheerio("*");
return this;
},
Backbone.View.prototype._createElement = function(tagName) {
return cheerio.load('<' + tagName + '>');
}
@akre54
Copy link

akre54 commented Mar 23, 2014

With a04d7da6, you no longer have to override all of _ensureElement. Just set a _createElement that looks like this:

Backbone.View.prototype._createElement = function(tagName) {
  return cheerio.load('<' + tagName + '>');
}

@nhunzaker
Copy link
Author

I wish gists sent out notifications about comments! I should have updated this, given I was the one that sent out the PR...

@akre54
Copy link

akre54 commented Apr 27, 2014

Good stuff :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment