StringTemplate 3: how to filter a list?

两盒软妹~` 提交于 2019-12-24 17:52:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!