Last active
August 29, 2015 14:21
-
-
Save jueyang/55bccd2b0e174333b514 to your computer and use it in GitHub Desktop.
This file contains 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
// notice that you are passing the data `arr` | |
// which, in your case, is the array of the restraurants | |
function putOnPage(arr){ | |
var listItemTemplate = _.template("<li><h2><%= name %></h2><h3><%= address %></h3><div><ul class='vioList'></ul></div></li>"); | |
// now you loop through each object in `arr` | |
// and get each individual `rest` | |
_.each(arr,function(rest,index){ | |
// you can access `rest.name`, `rest.address` | |
// because `name` and `address` are properties of `rest` | |
var listItem = listItemTemplate(rest); | |
$('#rest-list').append(listItem); | |
var violationTemplate = _.template("<li><p><%= description %></p></li>") | |
// can you tell me what the problem is here? | |
// hint: `rest.violations` is an array associated with each `rest` | |
_.each(arr,function(violation,index){ | |
var vioDes = violationTemplate(violation); | |
// once you figured out the above problem | |
// you'll find that here is another bug here | |
// hint: every time you loop through a `rest`, it looks like ALL the `.vioList` on the page so far will be selected | |
// how can you identify the `.vioList` associated with the desired `rest`? | |
// your turn to figure out :) | |
$('.vioList').append(vioDes); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment