javascript - How do I access a particular model in the templateHelper of a Collection View (or Layout)? -
roughly have this:
my collection; //a collection of models ids layout = backbone.marionette.layout.extend({ templatehelpers: { myfunc: function() { //this.items array of serialized models in collection } } }) layout = new layout({ collection: collection, })
the problem in myfunc()
can see model data in collection: available array this.items. there no key cannot this.items.get("the_one_i_want")
.
how can access individual model in case?
( in case doesn't suit use composite view , item view , put template helper on item view. )
correct me if i'm misunderstanding, seems me maybe you're looking "container methods" of in marionette, listed here: http://marionettejs.com/docs/backbone.marionette.html under "container methods".
so if have collection of models ids, rather than
this.items.get('the_one_you_want')
you'd write like
this.items.findbyindex('my_index')
i've never used findbyindex , there's little warning "this not guaranteed stable index." can search few other things, including cid , model itself.
again, may not understand situation, hope provides help... ian
Comments
Post a Comment