I want to grab the length of a collection to use in a random number generator. I want a view that shows one model of the collection, randomly generated. I'm using coffeescript, btw
So far I've tried stuff like
@collection.fetch
data:
id: Math.floor((Math.random()*@length)+1)
which won't work because the length isn't there until after it's fetched... I've tried a couple of other methods, such as grabbing after fetching, but length is always zero.
Anyone give me an idea of how to do this?
edit: javascript for those who can't read coffee
this.collection.fetch({
data: {
'id': Math.floor((Math.random() * length) + 1)
}
});