我在排序显示对象列表时遇到了问题
我有这个脚本
#set($dlService = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService"))
#set($dlTypeService = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryTypeLocalService"))
#set($dlVersionService = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileVersionLocalService"))
#if (!$entries.isEmpty())
<div class="row-fluid site">
<div class="">
<div class="grid" id="bubble-container">
<div style="width: 50%;" class="grid-sizer"></div>
#foreach ($entry in $entries)
#**
* GET DATA
*#
#set($fileEntry = $dlService.getDLFileEntryByUuidAndCompanyId($entry.getUuid(), $entry.getCompanyId()))
#set($fileEntryTypeId = $fileEntry.getFileEntryTypeId())
#set($fileEntryType = $dlTypeService.getDLFileEntryType($fileEntryTypeId))
#set($dlFileVersion = $dlVersionService.getLatestFileVersion($fileEntry.getUserId(), $fileEntry.getFileEntryId()))
#set($fieldsMap = $fileEntry.getFieldsMap($dlFileVersion.getFileVersionId()))
#set($isDark=false)
#set($Ueberschrift = "")
#set($URL = "")
#set($Teaser = "")
#foreach ($key in $fieldsMap.keySet())
#set($URL = $fieldsMap.get($key).get("url").getValue())
#set($Ueberschrift = $fieldsMap.get($key).get("ueberschrift").getValue())
#set($Teaser = $fieldsMap.get($key).get("teaser").getValue())
#set($isDark = $fieldsMap.get($key).get("schwarzerHintergrund").getValue())
#end
<div style="width: 50%; position: absolute; left: 0%; top: 0px;" class="grid-item">
#set($imageURL = $dlUtil.getPreviewURL($entry, $entry.getFileVersion(), $themeDisplay, ""))
#set ($additionalCss = "")
#if ($isDark)
#set ($additionalCss = "black")
#end
<a href="$URL">
<div class="bubble $additionalCss">
<h2>$Ueberschrift</h2>
<p>$Teaser</p>
</div>
<div class="bubble-icon">
<img src="$imageURL"/>
</div>
</a>
</div>
#end
</div>
</div>
</div>
#end
现在我想对外部foreach循环中的对象进行排序
我在https://velocity.apache.org/tools/devel/apidocs/org/apache/velocity/tools/generic/SortTool.html读过一些关于它的内容,但我无法扩展脚本并对对象进行排序 它必须是
之类的东西#foreach($ entries_sort.Sort中的$ entry($ entries,“getUuid”))
有人有提示吗?
最好的问候
答案 0 :(得分:2)
在Velocity中,您可以使用$sortTool
来提供排序方法。用法示例:
#foreach ($curEntry in $sortTool.sort($entries, 'entryId:asc'))
$curEntry
#end