Get the last view of an element from a CompositeView in Marionette

Can I get the latest ItemView from a Backbone CompositeView? I found a lot of documentation to get the latest model in the collection, but not the last view in the collection of views.

The reason I would like to do this is because I can make the last row in the table a little differently.

Below is the code that I'm using right now, it works fine, but it would be less “hacked” if I could get the correct ItemView from the CompositeView that created and displayed it. It uses jQuery to search for the entire part of the DOM contained in the CompositeView for the last element, then manipulates that element.

B.ListControl.View = Backbone.Marionette.CompositeView.extend({ itemView: ..., itemViewContainer: ..., template: ..., // ON RENDER onRender: function(){ // Add button to the last element in the list this.$el.find('div:last').text('Custome stuff goes here'); } }); 

Thanks!

+6
source share
1 answer

When your collection is received, you can get the last item as follows:

 this.children.findByIndex(this.children.length - 1); 

The nanny plugin provides many useful methods for you:

findByModel , findByCollection , findByCustom , findByIndex , findByCid

+10
source

Source: https://habr.com/ru/post/952911/


All Articles