Day 2: Creating Controllers

We now have models and views. When models change, views automatically update. Now how about combining them into components? Also, when the user presses the Edit or Delete button in the list of bookmarks, we want to edit or delete the corresponding bookmark. We need a place for that event-handling code. This is where controllers, or just controls as they are called in CanJS, come into the picture. Today we discuss four vital aspects of can.Control:

  1. Attaching a control to an element on the page

  2. Listening to UI events

  3. Using the data() function to retrieve a model from the page

  4. Using an observe to communicate between controllers

In doing so, we’ll create two controls: one for the bookmark list and one for the form that ...

Get Seven Web Frameworks in Seven Weeks now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.