Getting Started with Backbone I have a general view that can provide a collection as a list with a title I'm currently passing the archive and title in the Render method, but it seems a little strange. Is there another way that is more airborne?
Example:
var ListView = Backbone.View.extend ({template: _.template (["& lt; div & gt;", "& lt; % If the (title) {%> gt; <-H2> gt; & lt;% = Title%> & lt; / h2 & gt; & lt;%}% & gt; "," & lt; % If (item length = 0% gt; "," "," "," <% = itemTemplate (Item)%> "," & lt;%});% "", "", "& lt;%} other {%> gt; & lt; p & Gt; none. & Lt; / p & gt; & lt;%}% & gt; "," & lt; / div & gt; "]. Add ('')), itemtype: _template (" - <% = attributes.name%> (& lt;% = id% & gt;) "), render: function (item, title) {Var html = this.template ({items: items / * a collection * /, title: Sheer '', Item template: this.itemTemplate}); $ (this.el) .append (html);}}); var myView = new ListView ({el: $ ('# target')}); MyView.render (My Things, 'My Things'); MyView.render (Other Things, 'Other Things');
You initialize () function: start: function (attrs) {this.options = attrs; } So here you will pass properties as an object, such as:
New MyView ({some: "something", which is: "Something Now"}) Now you have values that you have passed in the simplest time during this example, in this. Option
console.log (this.options.Some) # "Something" console.log (this.options.that) # "Something else" / P> See var; Var Subview; View = Backbone.View.extend ({initialize: function (try (if (! (BackBone.Collection of this.collection inst.)) (A new type and ("This is not a qualification example backbone.cololution") } This.subViews = []; This.collection.forEach (function) {this.subViews.push (new subview ({model: model}}}}}}} (e) {console.error (e) }}, Render: function () {this.subViews.forEach (function (see) {this. $ El.append (see .rerer (. $ El);}, this); it returns;}}); SubView = Backbone.View.extend ({initialize: function () {try (if (this.model example backbone.model)) (Repeat new type of error ("This. BACKBOONE.COLATION ")}}} hold (E) {console.error (e);}}, render: function () {this return;}}); testCollection = new MyCollection (); CollectionView = new view ({ Collection: Test Collection}. $ ("Body") HTML (collectionView.render () $ L.); You can always use the Always collection model Should not handle, not just archive data.
Comments
Post a Comment