Code Monkey home page Code Monkey logo

backbone-todo's Introduction

backbone-todo-start

The start of the backbone-todo project

##Objective

Build a functioning (albeit simple) MV* task list project using Backbonejs

##Steps (day one) ###1: Create a Todo model.

  • Your model should have two attributes: title, and completed
  • completed should default to false

###2: Create a Todo view (and associated template).

  • The structure of your template should look something like this:

    <script type="text/template" id="todo-template">
      <... template here ...>
    </script>
  • The template code markup itself should be pretty simple:
    • An input of type="checkbox"
    • A label for the title
    • A button (with class="destroy") for deletion

Once you've created the template, create the View itself.

  • Don't forget to specify the template using underscore's template function
  • Make sure to create a render function that places the model.toJSON() into the template
  • Don't forget to make the use of this.$el when rendering

###3: Test your application

###4: Add the completed state

##Steps (day two) ###1: Add a toggle method to your model that simply toggles the completed state

###2: Add an event for when the check is clicked

  • The handler should call the model's toggle method
  • The handler should also trigger a re-render of the view
  • Go into your template and add the necessary logic for adding a completed css class to the label
  • Test your application by adding a todo and then clicking it 'complete'

###3: Add a delete event

  • Similarly, add an event to delete the todo when the delete button is pressed
  • Use backbone's built-in view method of remove to force the removal of the view ###4: Refactor your code
  • Take a look at the following code:
        initialize: function () {
	        this.listenTo(this.model, 'change', this.render);
	        this.listenTo(this.model, 'destroy', this.remove);
        },

The initialize method belongs in the backbone View. The view listens for changes on its model to trigger certain behaviors. Think about how you could refactor your code to take advantage of this simpler (and more efficient) method.

###5: (Black Diamond): Implement an 'edit' mode

  • When the user clicks on the label, make the field editable
    • Hint: have a hidden, absolutely positioned input that can be show/hidden when the view tells it to
    • When in 'edit' mode, the main label should be hidden and the input should show
    • The edit input should look seamless to the label
    • When the user presses enter, update the title of the model and re-render the view

backbone-todo's People

Contributors

brittonstanfill avatar cahlan avatar

Watchers

 avatar

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.