Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this small BackBone app correct? Am I using the conventions properly?
    text
    copied!<p>This is my simple Backbone app, I'm learning as I go. (It's written in coffeescript)</p> <p>The idea is, I have a x-y grid of pages (1-1, 2-1, 1-2, 2-2 etc.). The page loads, and instantiates a collection with these IDs. As the user navigates around (only left and right at the moment), the model loads from the server in it's entirety, including some HTML to display. </p> <p>It contains a model, and collection and a view, but I'm willing to bet I'm doing things in the wrong places! Please let me know what's wrong. </p> <pre><code>Page = Backbone.Model.extend displayHTML: (model, response) -&gt; $("#content").html(model.get('html')) Pages = Backbone.Collection.extend model: Page url: "/pages" current_page: '1-1' initialize: (models, options) -&gt; this.fetch(success: this.displayFirst) displayFirst: (collection, response) -&gt; model = collection.get(collection.current_page) model.fetch(success: model.displayHTML) nextPage: -&gt; id = "#{new Number(this.current_page[2]) + 1}-1" #todo - this will break with 9+ this.gotoPage(id) previousPage: -&gt; id = "#{new Number(this.current_page[2]) - 1}-1" #todo - this will break with 9+ this.gotoPage(id) gotoPage: (id) -&gt; this.current_page = id if model = this.get(id) model.fetch(success: model.displayHTML) else alert("Eh nooo") AppView = Backbone.View.extend el: $('body') events: "click #next-page": "nextPage" "click #previous-page": "previousPage" initialize: -&gt; this.pages = new Pages(null, {view:this}) nextPage: -&gt; this.pages.nextPage() previousPage: -&gt; this.pages.previousPage() appView = new AppView </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload