backbone.js - Backbone JS - Combination of collection, views and models -


i had following setup in 3 different projects, thought maybe it's worth asking here. there's chance i'm not person wondering this.

so there comes:

  • i have list of objects
  • the list items have special function draggable or onclick-events

my question: how build scenario backbone?

i guess create model , view list objects. use collection keeping objects.

now wonder: instantiate object view in model constructor , instantiate models in collection constructor? or there better way achieve want?

neither; use mediator instantiate views , inject them model/collection.

marionette.js has a nice implementation sort of mediating object, called controller - suggest check out.

further more, don't have explicitly instantiate collection models - declare type in collection's prototype, e.g.:

var mymodel = backbone.model.extend({     // shit });  var mycollection = backbone.collection.extend({     model: mymodel // pass type collection instantiate }); 

taking our mediator/controller approach further, how done (with marionette.js):

var mycontroller = marionette.controller.extend({     initialize: function () {         this.mycollection = new mycollection();         this.mycollectionview = new mycollectionview({             collection: this.mycollection         });     } }); 

this, of course, skeleton code, meant demonstrate mvc approach, it's starting point.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -