Created
October 27, 2011 18:51
-
-
Save TrisMcC/1320459 to your computer and use it in GitHub Desktop.
Backbone collection with metadata model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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