Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Attach ItemView instances at runtime to Backbone.marionette.Composite View
    text
    copied!<p>I am trying to add different views {Tabular View or Chart View} in a table. Each can have its own data. I am using Backbone Marionette for this and have following line of code. But item view is not render. </p> <p>html </p> <pre><code>&lt;script id="grid-template" type="text/template"&gt; &lt;div&gt; Data is displayed using Tabular View and Chart View ! &lt;/div&gt; &lt;/script&gt; &lt;script id="TabularViewTemplate" type="text/template"&gt; &lt;table&gt;&lt;tr&gt;&lt;td&gt;Value1&lt;/td&gt;&lt;td&gt;Value2&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/script&gt; &lt;script id="ChartTemplate" type="text/template"&gt; &lt;table&gt;&lt;tr&gt;&lt;td&gt;Value1&lt;/td&gt;&lt;td&gt;Value2&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/script&gt; &lt;div id="grid"&gt; &lt;/div&gt; ​ </code></pre> <p>JS</p> <pre><code>var ANBaseModel= Backbone.Model.extend({ name:"", type:"" }); var SSANModel= ANBaseModel.extend({ type:"SS" }); var BaseView=Backbone.Marionette.ItemView.extend({ template: "#row-template", tagName: "tr" , model:SSANModel }); // A Spreadsheet View var SSView= BaseView.extend({ render: function(){ alert(this.model.type); if(this.model.type=="SS") alert("Spreadsheet"); else if(this.model.type=="ChartAN") alert("Chart"); } }); // A Chart View var ChartView = BaseView.extend({ render: function(){ alert(this.model.type); if(this.model.type=="SS") alert("Spreadsheet"); else if(this.model.type=="ChartAN") alert("Chart"); } }); // The grid view var GridView = Backbone.Marionette.CompositeView.extend({ tagName: "table", template: "#grid-template", }); var SS= new SSANModel(); alert(SS.type); var objSSView=new SSView ({model:SS,template:"TabularViewTemplate"}); var gridView = new GridView({ itemView: objSSView }); gridView.render(); console.log(gridView.el); $("#grid").html(gridView.el); </code></pre> <p>JsFiddle: <a href="http://jsfiddle.net/Irfanmunir/ABdFj/" rel="nofollow">http://jsfiddle.net/Irfanmunir/ABdFj/</a></p> <p>How i can attach ItemView instances to composite View. Using this i can create different views having its own data . I am not using collection for composite view.</p> <p>Regards,</p>
 

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