I have a Product object. Product has 'awards'. award has id and name. If product has already have an award, it should be selected.
select#awards(multiple="multiple", name="awards[]")
for award in awards
- if ( product.awards.indexOf(award) != -1 )
option(value=award.id, selected) #{award.name}
- else
option(value=award.id) #{award.name}
But it is not working. I guess product.awards.indexOf(award) is not checking the equality of objects. What can I do?
You can try to compare ids:
- if ( product.awards.map(function(award) {return award.id}).indexOf(award.id) != -1 )