描述问题:
如题,filter过滤器未支持字符串数组
如何复现(请务必完整填写下面内容):
- 你是如何使用 amis 的?
sdk - amis 版本是什么?请先在最新 beta 版本测试问题是否存在
2.9.0 - 粘贴有问题的完整
amis schema
代码:
{
"type": "page",
"body": [
{
"type": "tpl",
"tpl": "${xxx|filter:a,b:match:keywords|json}",
"id": "u:d8233c2649f7"
}
],
"data": {
"xxx": [
{
"a": "a",
"b": "m"
}
],
"keywords": "m"
},
"id": "u:4202701508da",
"regions": [
"body"
]
}
以上schema能在tpl中按预期正常输出结果,如图:
但是data.xxx改为字符串数组时,就未能生效。
{
"type": "page",
"body": [
{
"type": "tpl",
"tpl": "${xxx|filter:match:keywords|json}",
"id": "u:d8233c2649f7",
"wrapperComponent": ""
}
],
"data": {
"xxx": ["a", "m"],
"keywords": "m"
},
"id": "u:4202701508da",
"regions": [
"body"
]
}
如图,其运行结果为表达式本身了:
按官网filter过滤器的文档说明,见:https://aisuda.bce.baidu.com/amis/zh-CN/docs/concepts/data-mapping#filter 使用方法为 ${xxx | filter[:keys][:directive][:arg1]}
,上面的测试结果表明 [:keys]
是必填项,只能用于对象数组?
2条答案
按热度按时间xzv2uavs1#
👍 Thanks for this!
🏷 I have applied any labels matching special text in your issue.
Please review the labels and make any necessary changes.
crcmnpdw2#
filter
确实没考虑字符数组的情况,不过新版公式应该可以使用${ARRAYFILTER(xxx, item => CONTAINS(item, keywords))}
参考: https://aisuda.bce.baidu.com/amis/zh-CN/docs/concepts/expression