StringTemplate 3:如何过滤列表? [英] StringTemplate 3: how to filter a list?

查看:84
本文介绍了StringTemplate 3:如何过滤列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用地图从列表(=多值属性)中删除特定元素?例如,假设我要过滤出给定列表中的所有b:

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]

期望的结果为"a,c",但实际结果为"a ,, c,"
事实是,映射成功地将b转换为null,但是随后将它们包装在匿名模板{}中,并成为非null值.因此,它们也不会通过strip()函数消失.

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?

更新

我找到了一种解决方法:

I've found a workaround:

filter(it) ::= "<if(it)><it><endif>"
<["a", "b", "c", "b"]: {<table.(it)>}: filter(); separator=",">

这给出了我想要的结果:a,c

This gives the result I wanted: a,c

推荐答案

可能不希望在您的模板中进行过滤,但是仍然可能是一个错误.

Might not want to filter in your template, but nonetheless, could be a bug.

好的,我检查了一下.这给出了空而不是空,因此认为它是一个项目. ST以相同的方式处理错误条件:空不为null.我认为您需要对模型进行过滤.

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.

这篇关于StringTemplate 3:如何过滤列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆