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