Ich muss durchlaufen List<Map<String, List<Map<String, String>>>>
und drucken Sie alle seinen Inhalt.Freemarker - Iterate durch verschachtelte Karten und verschachtelte Listen
Mein Problem ist, dass jedes Mal, wenn ich map Klammer-Syntax (like in the documentation) auf verschachtelten Ebenen verwende ich ein Syntaxproblem habe. Können Sie mir zeigen, wie verschachtelte Ebenen für einen Typ wie List<Map<String, List<Map<String, String>>>>
gehandhabt werden?
Ich habe dies getestet:
<!-- List<Map<String, List<Map<String, String>>>> -->
<#list myList as map1>
<!-- Map<String, List<Map<String, String>>> -->
<#list map1?keys as key1>
My Key: ${key1}
<!-- List<Map<String, String>> -->
<#list map1[key1] as map2>
<!-- Map<String, String> -->
<#list map2?keys as key2>
My Key: ${key2} | My Value: ${map2[key2]}
</#list>
</#list>
</#list>
</#list>
Und ich habe diesen Fehler:
java.lang.RuntimeException: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> map1[key1] [in template "hello.html" at line 39, column 32]
----
Tip: It's the final [] step that caused this error, not those before it.
----
Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: #list map1[key1] as map2 [in template "hello.html" at line 39, column 25]
----
ich verwende Freemarker 2.3.23. Vielen Dank.
Können Sie die nicht arbeitende Vorlage Schnipsel zitieren? – ddekany
Ich habe mein Thema mit dem nicht funktionierenden Template-Snippet aktualisiert :) – Gugelhupf
Haben Sie überprüft, was der Wert von 'key1' ist, wo es fehlschlägt? – ddekany