eg-259:ch15
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
eg-259:ch15 [2013/03/05 20:09] – [Initialize View] eechris | eg-259:ch15 [2013/03/05 20:44] (current) – [Complete CRUD App (in-memory storage)] eechris | ||
---|---|---|---|
Line 459: | Line 459: | ||
- | ===== Define Model ===== | + | ===== Router |
- | <code javascript> | + | Here we have a more complex example using three templates: |
- | (function ($) { | + | * One for the Project list |
+ | * One for the project detail -- including a form for editing the title of the selected project | ||
+ | * One to render the list items themselves. | ||
+ | Here is the code: | ||
+ | [[http:// | ||
- | Project | + | ===== App Router ===== |
- | firstProject | + | <code javascript> |
- | | + | AppRouter |
+ | | ||
+ | "": | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | home: function () { | ||
+ | console.log('home'); | ||
+ | new HomeView(); | ||
+ | }, | ||
+ | add: function () { | ||
+ | console.log(' | ||
+ | new AddView(); | ||
+ | } | ||
}); | }); | ||
- | |||
- | })(jQuery); | ||
</ | </ | ||
- | [[http:// | + | ---- |
- | ===== Define Model ===== | + | The purpose of the router is to define some " |
- | <code javascript> | + | ===== Router Initialisation |
- | (function ($) { | + | |
- | + | ||
- | Project | + | |
- | + | ||
- | firstProject | + | |
- | title: ' | + | |
- | }); | + | |
- | + | ||
- | })(jQuery); | + | |
- | </ | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | ===== Define Model ===== | + | |
<code javascript> | <code javascript> | ||
- | (function ($) { | + | $(document).ready(function () { |
- | + | | |
- | | + | |
- | + | }); | |
- | | + | |
- | title: ' | + | |
- | }); | + | |
- | + | ||
- | })(jQuery); | + | |
</ | </ | ||
- | [[http:// | + | ---- |
- | ===== Define Model ===== | + | Here we create a new object representing the whole application as an '' |
- | <code javascript> | + | ===== Events ===== |
- | (function ($) { | + | |
- | Project = Backbone.Model.extend({}); | + | In the second router example [[http:// |
- | firstProject | + | ===== Views Listening to Events ===== |
- | title: ' | + | |
- | }); | + | |
- | })(jQuery); | + | In the final iteration [[http:// |
- | </code> | + | |
- | [[http:// | ||
- | ===== Define Model ===== | ||
- | <code javascript> | + | ===== Complete CRUD App (in-memory storage) ===== |
- | (function ($) { | + | |
- | Project = Backbone.Model.extend({}); | + | * This final version of the app includes a facility for showing existing projects and allowing their titles to be edited. |
+ | * The app now has an '' | ||
+ | * It overrides the '' | ||
+ | * View the code for insight into how this works | ||
- | firstProject = new Project({ | + | [[http:// |
- | title: ' | + | |
- | }); | + | |
- | + | ||
- | })(jQuery); | + | |
- | </ | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | ===== Application Router ===== | + | |
- | ===== Events ===== | + | |
- | ===== Complete CRUD App (in-memory storage) ===== | + | |
===== Summary of this Session ===== | ===== Summary of this Session ===== | ||
Line 552: | Line 533: | ||
* [[eg-259: | * [[eg-259: | ||
* [[eg-259: | * [[eg-259: | ||
- | ===== Homework Exercises ===== | ||
- | - Come up with something | ||
eg-259/ch15.1362514196.txt.gz · Last modified: 2013/03/05 20:09 by eechris