Possible to sort an array of maps on multiple criteria?
Is it possible to sort an array of maps on multiple criteria?
For example could I sort the below by count & then title? I tried the addSortCriterion but that gave me an error.
#set ($menuItems= [])
#set ($tmp = $menuItems.add({"title" : "item1", "count" : 5, "url" : "http://www.google.com"}))
#set ($tmp = $menuItems.add({"title" : "item3", "count" : 3, "url" : "http://www.google.com"}))
#set ($tmp = $menuItems.add({"title" : "item4", "count" : 2, "url" : "http://www.google.com"}))
#set ($tmp = $menuItems.add({"title" : "item2", "count" : 3, "url" : "http://www.google.com"}))
#foreach ($item in $_SortTool.sort($menuItems, 'count:desc'))
<a href="$item.url">$item.title</a>
#end
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 17 Feb, 2015 07:29 PM
Hi,
The Sort Tool can sort by multiple properties by supplying them as an array. For example:
For information on this functionality can be found on this page.
Please let me know if you have any questions.
Thanks!
2 Posted by webteam on 17 Feb, 2015 07:52 PM
Thank you!
webteam closed this discussion on 17 Feb, 2015 07:53 PM.