StringTemplate 3: how to filter a list?

2019-08-02 12:02发布

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条回答
何必那么认真
2楼-- · 2019-08-02 12:31

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.

查看更多
登录 后发表回答