Jan
Jan

Reputation: 3401

How to list my results in a for loop

If i have this snippet from my action

for (c in AuthorList){
    def bookCount = Book.countByName(c)
}

How do i make my bookCount into a list

Upvotes: 0

Views: 48

Answers (2)

dmahapatro
dmahapatro

Reputation: 50275

for loop is not required at all. ;)

authorList.collect { Book.countByName( it ) }

should give the list you are looking for.

Upvotes: 1

Phat H. VU
Phat H. VU

Reputation: 2370

Try to use <<

def list = []

for (c in AuthorList){
    def bookCount = Book.countByName(c)
    list << bookCount
}

Upvotes: 0

Related Questions