jquery - Marionette CompositeView attachHtml after rather than append -


i have model , parent child relationship i'd display in table display each parent followed children, i'll indent children slightly. i'm there can seem append children parent row rather adding them after parent row.

view.treeview = backbone.marionette.compositeview.extend({   template: listitemtpl,   tagname: "tr",   initialize: function() {     var children = new backbone.collection(this.model.get('children'));     if (this.model.get('parent')) {       this.$el.addclass('child');     } else {       this.$el.addclass('parent');     }     this.collection = children;   },    attachhtml: function(collectionview, childview, index) {     collectionview.$el.append(childview.el);   } });  view.treeroot = backbone.marionette.compositeview.extend({   tagname: "table",   classname: "table table-bordered table-striped",   childview: view.treeview,   template: listtpl,   childviewcontainer: "tbody" }); 

i've tried

collectionview.$el.after(childview.el); 

but doesn't work @ all.

my model parent child created server side using sailsjs below.

module.exports = {   schema: true,   attributes: {     name: 'string',     category: {       model: 'category'     },     parent: {       model: 'term'     },     children: {       collection: 'term',       via: 'parent'     }   } }; 

i had similar problem , ended using multiple tables instead.. putting parent object in thead , children in tbody.

so tip if wanna go way:

use compositeview it's model being parent object, collection children , it's template being table. display model data inside thead section, make childviewcontainer tbody , use tr tagname.

(thanks jsteunou @ github)

list.child = app.views.itemview.extend({   template: "urltotemplate",   tagname: 'tr' });  list.parent = app.views.compositeview.extend({   template: "urltotemplate",   tagname: 'table',   childview: list.child,   childviewcontainer: 'tbody',    initialize: function(options){     this.collection = this.model.get("children");   } });  list.parents = app.views.compositeview.extend({   template: "urltotemplate",   childview: list.parent,   childviewcontainer: 'div.container'  }); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -