Backbone study Diary first episode--hello backbone

Source: Internet
Author: User

because Work items need to use backbone.js this MVC framework, so the previous period of time has been online collection of long-range information, but there is nothing better, accidentally found the www.the5fire.com site has backbone full set of tutorials, so again when the back chop Hand family bought this ebook, but many reasons have been Not how to see, today in the bus bored, turned over the phone suddenly remembered this book, in the car saw 2 chapters, also good, have aroused my desire to learn from him, back home can not wait to finish the housework, began code.

Here's the example I wrote a Hello backbone demo this evening.

1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title></title>67<body>8<button id= "Check" > Novice registration </button>9<ul id= "World-list" ></ul>Ten  One<script type= "Text/javascript" src= "Scripts/jquery-1.11.1.js" ></script> A<script type= "Text/javascript" src= "Scripts/underscore.js" ></script> -<script type= "Text/javascript" src= "Scripts/backbone.js" ></script> -<script> the(function($){ -World=Backbone.Model.extend ({ -NameNULL  //Create a World object with the Name property -         }); +  -worlds=Backbone.Collection.extend ({ +             //collection of World Objects AInitializefunction(models,options) { at                  This. bind (' Add ', - Options.view.addOneWorld -                 ); -             } -         }); -  inappview=Backbone.View.extend ({ -el:$ (' body '), toInitializefunction(){ +                  This. worlds=NewWorlds (NULL,{//constructor, instantiate a Worlds collection class, and pass in the Appview object as a dictionary -View This the                 }); *             }, $ events:{Panax Notoginseng' Click #check ': ' CheckIn '//event bindings, binding elements in the DOM with ID check -             }, theCheckIn:function(){ +                 varWorld_name=prompt ("Which world are you from?")); A                 if(world_name== "){ theWorld_name= ' Unknown ' +                 } -                 varWorld=NewWorld ({name:world_name}); $                  This. Worlds.add (world); $             }, -Addoneworld:function(model) { -$ (' #world-list '). Append (' <li> here is from <b> ' + theModel.get (' name ') + -' </b> 's Greetings: Hello backbone! </li> ')Wuyi             } the         }); -         varappview=NewAppview; Wu }) (JQuery) -</script> About</body> $

Backbone is an excellent MVC framework, model represents a data model, collection is a collection of models, and view is used to process pages and simple page logic.

Backbone study Diary first episode--hello backbone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.