Giter Club home page Giter Club logo

now-backbone's Introduction

NOW That's What I Call Backbone

We have come a long way from our mixtape days. You're a little older, wiser and now know some new, slick technologies.

With this exercise, we are going to make a relatively simple backbone application (from scratch!) that will display the track list of a mix cd. To make it even more slick, when we click on a song title, the artists name will appear below the title. WILD!

Let's jump in!

Setup

We have already set up the Webpack template for you to get started. It comes pre-loaded with all of beautiful libraries that will help us make a great application: Backbone, jQuery and Underscore. It also has a starter app.js file as well as models and collections folders.

Since we are set up with Webpack, you'll want to run npm install once to set this project up. To start your development server, you'll want to run npm start.

Take a moment to examine the folder structure before moving on.

Initial Data

Our mix CD will be based on a hard-coded array of objects with song data. We've gotten you started here with the structure of one song, so go ahead and copy this code to your app.js file, above the $(document).ready():

const songData = [
    {
        title: "Drop It Like It's Hot",
        year: 2004,
        artist: "Snoop Dog"
    }
  ];

Then add a few more songs to your collection that you like!

Models

Next up, we'll want to create a Model to store our song's information.

Model File

  1. You will create a new model file in the src/app/models folder
  2. Write the code that you need to create an empty model called Song in this new file

Use the Model

Make some updates to the app.js file.

  1. Add the code to load the new Model
  2. Create an instance of your model object
  3. Log some information about the model instance to ensure it was created successfully

View the Model Data

  1. There is an Underscore template stub already created for you in the dist/index.html file. Update this template to display some of the song fields that you want to see displayed.
  2. Compile the template in app.js in the appropriate section of code
  3. Invoke the compiled template to generate the HTML for the model instance created above
  4. Add the song's HTML to the DOM (check out index.html to see where you'd like to add it)

Collections

Next, we'll create a collection.

Collection File

  1. Create a new collection file in the src/app/collections folder
  2. Add the code to load in the Song model
  3. Write the code that you need to create a collection called SongList which will contain Song model objects

Use the Collection

Make some updates to the app.js file.

  1. Add the code to load the new collection
  2. Instantiate the collection using the songData array you created earlier
  3. Add the model instance that you created in the previous step to the collection using the collection's add method

View the Collection Data

  1. Using the Underscore tempate you created in the model section to render the data for each Song within the collection

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.