Freemarker:在对象数组中找到一个结果

时间:2015-08-25 18:26:39

标签: arrays multidimensional-array freemarker template-engine

我有如下数组:

# Remove www from URL
RewriteCond %{HTTP_HOST} ^www\.example\.org$ [NC]
RewriteRule ^(.*)$ http://example.org/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} \ /+(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.org/$1 [R=302,L]

# Remove index from home URL
RewriteCond %{THE_REQUEST} \ /+(.*)index\.php
RewriteRule ^(.*)index\.php$ http://%{HTTP_HOST}/$1 [R=301,L]

# Remove the search folder:
RewriteCond %{THE_REQUEST} \ /+search/search
RewriteRule ^search/search(.*)$ /search$1 [L,R=301]

# Add the search folder back
RewriteCond $1 !^/search
RewriteRule ^search(.*)$ /search/search$1 [L]

# Add the extension back on if it exists
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

我知道id ..示例 22 。我需要这样的东西:

<#assign services = [
{'id': '1', 'name': 'AAAA'},
{'id': '22', 'name': 'BBBB'}
]>

我尝试了这个但没有结果

${services[2].name} // print BBBB

有没有办法做到这一点?

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

您可以循环services数组。

<#assign services = [
{'id': '1', 'name': 'AAAA'},
{'id': '2', 'name': 'BBBB'},
{'id': '22', 'name': 'CCCC'},
{'id': '23', 'name': 'DDDD'}
]>

<#list services as service>
   <#if service.id == '22'>
        Result: ${service.name}
    </#if>
</#list>