Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat does Backbone.js or other MVC offer?
    primarykey
    data
    text
    <p>I'm beginning with backbone.js</p> <p>Going through some tutorials, like the one shown below. I got the feeling, it is really more about how to organize your objects and how to instruct them to interact. And I can do them without backbone.js So backbone.js looks more like a set of rules, philosophies to me, then an actual plug-in for the most part. Is that what it is?</p> <pre><code>(function($){ var Item = Backbone.Model.extend({ defaults: { part1: 'hello', part2: 'world' } }); var List = Backbone.Collection.extend({ model: Item }); var ListView = Backbone.View.extend({ el: $('body'), events: { 'click button#add': 'addItem' }, initialize: function(){ _.bindAll(this, 'render', 'addItem', 'appendItem'); // remember: every function that uses 'this' as the current object should be in here this.collection = new List(); this.collection.bind('add', this.appendItem); // collection event binder this.counter = 0; this.render(); }, render: function(){ $(this.el).append("&lt;button id='add'&gt;Add list item&lt;/button&gt;"); $(this.el).append("&lt;ul&gt;&lt;/ul&gt;"); _(this.collection.models).each(function(item){ // in case collection is not empty appendItem(item); }, this); }, // `addItem()` now deals solely with models/collections. View updates are delegated to the `add` event listener `appendItem()` below. addItem: function(){ this.counter++; var item = new Item(); item.set({ part2: item.get('part2') + this.counter // modify item defaults }); this.collection.add(item); // add item to collection; view is updated via event 'add' }, // `appendItem()` is triggered by the collection event `add`, and handles the visual update. appendItem: function(item){ $('ul', this.el).append("&lt;li&gt;"+item.get('part1')+" "+item.get('part2')+"&lt;/li&gt;"); } }); var listView = new ListView(); })(jQuery); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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