GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — fullstack-javascript/05-backbone/binding/index.html at master · sahmedgithub/fullstack-javascript Expand file tree/ Copy pathindex.htmlMore file actions 90 lines (81 loc) · 2.33 KB / Copy pathindex.htmlFile metadata and controls90 lines (81 loc) · 2.33 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 <!DOCTYPE> <html> <head> <script src="jquery.js"></script> <script src="underscore.js"></script> <script src="backbone.js"></script> <script> var appleData = [ { name: 'fuji', url: 'img/fuji.jpg' }, { name: 'gala', url: 'img/gala.jpg' } ] var app var router = Backbone.Router.extend({ routes: { '': 'home', 'apples/:appleName': 'loadApple' }, initialize: function(){ var apples = new Apples() apples.reset(appleData) this.homeView = new homeView({collection: apples}) this.appleView = new appleView({collection: apples}) }, home: function(){ this.homeView.render() }, loadApple: function(appleName){ this.appleView.loadApple(appleName) } }) var homeView = Backbone.View.extend({ el: 'body', template: _.template('Apple data: <%= data %>'), render: function(){ this.$el.html(this.template({data: JSON.stringify(this.collection.models)})) } }) var Apples = Backbone.Collection.extend({ }) var appleView = Backbone.View.extend({ initialize: function(){ this.model = new (Backbone.Model.extend({})) this.model.on('change', this.render, this) this.on('spinner', this.showSpinner, this) }, template: _.template('<figure>\ <img src="<%= attributes.url%>"/>\ <figcaption><%= attributes.name %></figcaption>\ </figure>'), templateSpinner: '<img src="img/spinner.gif" width="30"/>', loadApple: function(appleName){ this.trigger('spinner') var view = this // We'll need to access that inside of a closure setTimeout(function(){ // Simulates real time lag when fetching data from the remote server view.model.set(view.collection.where({name: appleName})[0].attributes) }, 1000) }, render: function(appleName){ var appleHtml = this.template(this.model) $('body').html(appleHtml) }, showSpinner: function(){ $('body').html(this.templateSpinner) } }) $(document).ready(function(){ app = new router Backbone.history.start() }) </script> </head> <body> <div></div> </body> </html> |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |