问题
How can I remove specific elements from a list(=multi-valued-attribute) using a map? For example, let's say I want to filter out all b's in a given list:
<["a", "b", "c", "b"]: {<table.(it)>}; separator=",">
table ::= ["b":, default: key]
The desired outcome would be "a,c" but the actual result is "a,,c,"
The thing is that the map successfully turn b's into nulls, but then they're wrapped in an anonymous template {} and become non-null values. So they won't go away with strip() function, either.
So the question is, would it be possible to filter a list using a map by slightly modifying the code above?
update
I've found a workaround:
filter(it) ::= "<if(it)><it><endif>"
<["a", "b", "c", "b"]: {<table.(it)>}: filter(); separator=",">
This gives the result I wanted: a,c
回答1:
Might not want to filter in your template, but nonetheless, could be a bug.
Ok, i checked it out. That gives empty not null so it thinks it's an item. ST treats false conditionals same way: empty not null. I think you need to filter in model.
来源:https://stackoverflow.com/questions/13366345/stringtemplate-3-how-to-filter-a-list