0

I'm trying to create a simple list using Marionette's CollectionView and ItemView.

iv = Marionette.ItemView.extend({
    tagName: "li",
    className: "card",
    template: _.template("empty-template")
});

cv = Marionette.CollectionView.extend({
    tagName: "ul",
    className: "card-list",
    childView: iv
});

collection = new Backbone.Collection([
    { name: "alice" },
    { name: "bob" },
    { name: "carol" }
);

view = new cv({collection: collection});
view.render()

This works just fine, creates the list with three items and no content (the template is empty). But the on html code produced everything is stuck together, with no line breaks. Like this:

<ul class="card-list"><li class="card"></li><li class="card"></li><li class="card"></li></ul>

Is there a way of getting this instead?

<ul class="card-list">
<li class="card"></li>
<li class="card"></li>
<li class="card"></li>
</ul>

jsFiddle

EDIT: Any type of space would do. The li are inline-block and need to be spaced to be able to use justify on the ul.

JayC
  • 2,014
  • 4
  • 15
  • 25
  • is there a reason why you need to have the line break? – josephnvu Oct 05 '15 at 01:21
  • Not necessarilly a line break but any type of space. I assumed a line break would be more logical. I'm trying to create a grid, the `li` are `inline-block` and need to be spaced so `ul` with `text-align: justify` can properly manage the space between items. As it is now, all items are packed together. – JayC Oct 05 '15 at 06:51

1 Answers1

1

Ok this is a guess, but maybe you can just change the default handler of attaching the html. So your "cv" code will look like this:

cv = Marionette.CollectionView.extend({
    tagName: "ul",
    className: "card-list",
    childView: iv,
    attachBuffer: function(collectionView, buffer) {
        collectionView.$el.append(buffer + '\n');
    },
});
josephnvu
  • 1,210
  • 1
  • 9
  • 14
  • I was hoping not to have to change `attachBuffer` or any of the internals, but looks like I will have to... – JayC Oct 05 '15 at 06:56
  • Just tried the solution and it's not working, the updated fiddle is here http://jsfiddle.net/pac4u993/2/ – JayC Oct 06 '15 at 11:34