Exercise 4 - Fetching and rendering a Collection
In this creative exercise, we will be putting all of our skills from the day together. Do as much as you can in the time that we have.
Feel free to follow the instructions below, or branch out to practice skills at your own pace!
- If you didn't finish the last exercise, download the solution files from here.
- Continue from your previous files or the solution files.
- If you are not yet running your code from a local server, do that now by following
these instructions. We need to do this because of security restrictions on file:// protocol with XMLHttpRequests.
Instructions - Add Yourself
- Instantiate a new Person that is you, and give yourself a unique "id" attribute
- There is a JSON REST API at http://gdibb.herokuapp.com/people that you can use from your app.
- Add the
urlRoot to the Person Model.
.save() to add yourself to the collection
- If you are successful, you will see yourself at http://gdibb.herokuapp.com/people
Instructions - Fetching the Collection
- Using the API, add the
url to the People collection.
.fetch() on the collection.
- Make sure that your view knows when to update. For this, you can create an event listener on the collection for 'reset'.
Instructions - Get Creative!
- Add events to the page, style it with CSS, or make an interface to add or edit the people in your rolodex.
- When you are done, set a
finished property on your Model to
true and save it to the server!
Bonus - Parsing the Models
- Some of the models from the server might be inconsistent - use model.parse() to clean them up before the template gets rendered