/app/scripts/collections/prediction-collection.js
https://github.com/davidchchang/mystops · JavaScript · 31 lines · 23 code · 7 blank · 1 comment · 1 complexity · f6f56bbe0f4c9db44bed4464ccd56e04 MD5 · raw file
- /*global mystops, Backbone*/
- mystops.Collections.PredictionCollection = Backbone.Collection.extend({
- model: mystops.Models.PredictionModel,
- url: 'http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=ttc',
- comparator: function (model) {
- return +model.get('minutes');
- },
- parse: function (data) {
- var parsed = [];
- $(data).find('direction').each(function (index) {
- var dataDir = $(this).attr('title');
- $(this).find('prediction').each(function (index) {
- var dataMins = $(this).attr('minutes');
- parsed.push({minutes: dataMins, direction: dataDir});
- });
- });
- return parsed;
- },
- fetch: function (options) {
- options = options || {};
- options.dataType = "xml";
- Backbone.Collection.prototype.fetch.call(this, options);
- }
- });