I have a CompositeView with its template, and ItemView with its template. all right!
But now I want to wrap two itemView into a same div, i.e.
The first ItemView, and the second ItemView into a The third ItemView, and fourth itemView into other ... etc
I know that I can use the ItemIndex in template of ItemView.. but I don't know use this value in template of Composite View
I have:
Pagination.ItemView = Marionette.ItemView.extend({
template: PaginationItemView,
});
Pagination.ItemsListView = Backbone.Marionette.CompositeView.extend({
itemViewContainer: 'span',
itemView: Pagination.ItemView,
itemViewOptions: function(model, index) {
return {
itemIndex: index
}
}
});
My template of ItemView is:
<script>
<div style="margin-bottom:25px;height: 47%;" class="col-lg-6 col-xs-12 clearfix">
<div class="col-xs-3">
<!-- photo >
</div>
<div class="col-xs-9 box-basic">
<!-- info about item>
</div>
</div>
</script>
I want something as :
<div class="row">
<tagName of itemView>
first ItemView
<end tagName of ItemView>
<tagName of itemView>
seconde ItemView
<end tagName of ItemView>
</div>
<div class="row">
<tagName of itemView>
third ItemView
<end tagName of ItemView>
<tagName of itemView>
fourth ItemView
<end tagName of ItemView>
</div>
Any idea ? thanks in advance!
EDIT:
I have a solution, But really it not is correct.
In the template of compositeTemplate.html
<script>
<span>
<div class="row" id="cont1">
</div>
<div class="row" id="cont2">
</div>
<div class="row" id="cont3">
</div>
</span>
</script>
And in the CompositeView.js
appendHtml: function(collectionView, itemView, index){
var childrenContainer = collectionView.itemViewContainer ? collectionView.$(collectionView.itemViewContainer) : collectionView.$el;
var children = childrenContainer.children();
$("#cont"+(index%3+1)).append(itemView.el);
},
Somebody know do it of correct way?