Skip to content

Instantly share code, notes, and snippets.

@fduch2k
Forked from TrisMcC/Counts.js
Created February 11, 2012 13:29
Show Gist options
  • Select an option

  • Save fduch2k/1799427 to your computer and use it in GitHub Desktop.

Select an option

Save fduch2k/1799427 to your computer and use it in GitHub Desktop.
Backbone collection with metadata model
Collection.Counts = Backbone.Collection.extend({
Model: Model.CountResult,
url: function() {
return '../EmailCounts/CountResults.php';
},
sync: function(method, model, options) {
options = _.extend({
dataType: 'html',
type: 'POST',
url: this.url()
}, options);
return $.ajax(options);
},
parse: function(response) {
var models = [];
var html = $(response);
html.find('tr:has(td)').each(function() {
var row = $(this);
models.push({
vendor: row.find(':eq(0)').text(),
companyCount: +row.find(':eq(1)').text().replace(',', ''),
emailCount: +row.find(':eq(2)').text().replace(',', '')
});
});
this.countInfo = new Model.CountInfo({
sql: html.find('textarea[name=SQL]').text()
});
return models;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment