Last active
August 29, 2015 14:16
-
-
Save lukecampbell/f4ac42c4a4c3e200e197 to your computer and use it in GitHub Desktop.
Example responses
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
{ | |
"categories" : [ | |
{ | |
"id": "temperature", | |
"name":"Temperature" | |
}, | |
{ | |
"id" : "nutrients", | |
"name" : "Nutrients" | |
}, | |
{ | |
"id":"Currents", | |
"name":"Currents" | |
} | |
] | |
} | |
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
TOCView -> | |
subviews : [] | |
stationCollection, | |
categoryCollection | |
add: function(subview) { // CategoryItemView | |
subview.render(); // --> <li> {{ name }} <ul></ul> </li> | |
this.subviews.push(subview); | |
this.$el.find('ul').append(subview.el); | |
} | |
render: function() { | |
var self = this; | |
this.$el.html(this.template()); // <ul class="fancy-toc"> <li> Search box would potentially go here </li> </ul> | |
this.categoryCollection.each(function(category) { | |
// Get a new collection of only the stations for this category | |
//-------------------------------------------------------------------------------- | |
var relevantCollection = new StationCollection(); | |
var relevantStations = self.stationCollection.filter(function(item) { | |
if(category in item.get('categories')) { | |
return true; | |
} | |
return false; | |
}); | |
// now I have a collection of only the stations for this category | |
relevantCollection.reset(relevantStations); // takes an empty collection and instatinates with a list of models | |
//-------------------------------------------------------------------------------- | |
var subview = new CategoryView({ | |
model: category, | |
collection: relevantCollection | |
}); | |
this.add(subview); | |
} | |
} | |
CategoryItemView -> | |
tagName: "li" | |
className: "special-sauce" | |
subviews: [] | |
add: function(subview) { | |
subview.render(); // --> <li> Station Name </li> | |
this.subviews.push(subview); | |
this.$el.find('ul').append(subview.el); | |
} | |
render: function() { | |
this.$el.html(this.template({collection: this.collection})); // | |
this.collection.each(function(model) { | |
var subview = new StationItemView({ | |
model: model | |
}); | |
this.add(subview); | |
} | |
} | |
StationItemView -> | |
tagName: "li" | |
render: function() { | |
this.$el.html(this.template({ model: this.model })); | |
} | |
var stations = { | |
"stations" : [ | |
{ | |
"id":"tollsps", | |
"categories" : ["temperature", "nutrients"], | |
"lat": 40, | |
"lon": -80 | |
} | |
] | |
} | |
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
{ | |
"stations" : [ | |
{ | |
"id":"tollsps", | |
"cateogories" : ["temperature", "nutrients"], | |
"lat": 40, | |
"lon": -80 | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment