2

我在liferay中创建的结构如下图所示:

{
    "availableLanguageIds": [
        "en_US"
    ],
    "defaultLanguageId": "en_US",
    "fields": [
        {
            "label": {
                "en_US": "Image"
            },
            "predefinedValue": {
                "en_US": ""
            },
            "style": {
                "en_US": ""
            },
            "tip": {
                "en_US": "Upload the image to be displayed in the Small Banner"
            },
            "dataType": "image",
            "fieldNamespace": "ddm",
            "indexType": "keyword",
            "localizable": true,
            "name": "smallImage",
            "readOnly": false,
            "repeatable": true,
            "required": true,
            "showLabel": true,
            "type": "ddm-image",
            "nestedFields": [
                {
                    "label": {
                        "en_US": "Priority of Image"
                    },
                    "predefinedValue": {
                        "en_US": "0"
                    },
                    "style": {
                        "en_US": ""
                    },
                    "tip": {
                        "en_US": "Priority of the uploaded Image. Lower the number, higher the priority."
                    },
                    "dataType": "integer",
                    "fieldNamespace": "ddm",
                    "indexType": "keyword",
                    "localizable": true,
                    "name": "imagePriority",
                    "readOnly": false,
                    "repeatable": false,
                    "required": true,
                    "showLabel": true,
                    "type": "ddm-integer"
                }
            ]
        }
    ]
}

现在在模板中,我想使用图像的优先级字段对其进行排序。我的模板如下图所示:

<div id="example2" class="slider-pro">
    <div class="sp-slides">
        <#if smallImage.getSiblings()?has_content>
            <#list smallImage.getSiblings()?sort_by(["properties","imagePriority"]) as cur_smallImage>
                <#if cur_smallImage.getData()?? && cur_smallImage.getData() != "">
                    <div class="sp-slide">
                        <img class="sp-image" alt="${cur_smallImage.getAttribute("alt")}" src="${cur_smallImage.getData()}" data-src="${cur_smallImage.getData()}" data-retina="${cur_smallImage.getData()}" />
                    </div>
                </#if>
            </#list>
        </#if>
    </div>
</div>

我也尝试将 ?sort_by("cur_smallImage.imagePriority") 排序为?sort_by(" imagePriority ")但它没有用。我想按指定的优先级顺序显示图像。
请帮忙。

4

1 回答 1

0

如果要用于排序的子变量在更深层次上(即,如果它是子变量的子变量等),则可以使用序列作为参数,指定子变量的名称这导致所需的子变量。例如:

<#assign members = [
    {"name": {"first": "Joe", "last": "Smith"}, "age": 40},
    {"name": {"first": "Fred", "last": "Crooger"}, "age": 35},
    {"name": {"first": "Amanda", "last": "Fox"}, "age": 25}]>

按名称排序。最后:

<#list members?sort_by(['name', 'last']) as m>
- ${m.name.last}, ${m.name.first}: ${m.age} years old
</#list>

取自: https ://freemarker.apache.org/docs/ref_builtins_sequence.html#ref_builtin_sort_by

于 2019-09-14T11:41:00.993 回答