walmartlabs/thorax

rendering view inside collection

Closed this issue · 3 comments

Hi!

I have the following problem.
There is a collection in my view and I want to wrap each of it's child views with li tag to have structure like this:

<ul>
  <li>childView</li>
  <li>childView</li>
</ul>

So i try to render view inside a collection..

{{#collection tagName="ul"}}
  <li>
    {{view cv}}
  </li>
{{/collection}}

..and I had to create a node view like this to get access to a view instance

var NodeView = Thorax.View.extend({
  initialize: function() {
    this.cv = this;
  }
})

As a result I get nested-render error.
If cw is some other view, it works fine.
Help me please.
How can I manually wrap my view into something? (I don't want to put li tags inside a node view)
Is it possible to get a child view instance inside a collection tag.

You're creating a circular loop where the view attempts to render itself. If the throw wasn't in place you'd likely end up with a stack overflow due to the view attempting to render itself over and over.

I'm not clear on what exactly you're trying to do here, but you may want to look into item-view, if you'd like to create a view for each element in a collection.
http://thoraxjs.org/api.html#collection

Seems that you have misunderstood my question. item-view is not very helpful for me because I can set an itemView attribute in a collection view. Actually I do so, rendering with {{collection}} tag to avoid error, so my item template looks like this:

<li>
  <div class="item">
    <strong>item title</strong>
    item prop: {{foo}}
  </div>
</li>

But <li> tags are not part of an item. I think, they refer to a collection, so I would like to deal with them in a collection template.
By the way I don't understand, why a stack overflow may occur. I only want to render a view inside a collection. My view does'nt contain the same collection and I don't render a collection within intself. Item view and collection view are two different views, aren't they?

Oh, I found the solution!
The easiest way to solve my problem is to use tagName attribute.
But I still want to know, if I can describe wrapper tags in a collection template.