主题
where
保留属性与某个取值精确匹配的数组条目。
语法
knap
{{ value | where:("published", true) }}
{{ value | where:("status", "draft") }}
{{ value | where:("author.name", "Ada") }}用法
- 带引号的属性路径和比较取值都是必填的。点分路径用于选取嵌套的自有属性。
- 字符串、数字、布尔值和
null按类型和取值比较。 - 缺失的属性永远不会匹配,比较取值为
null时也是如此。 - 匹配到的条目会保留其类型和原有顺序。
示例
布尔属性
json
{
"posts": [
{
"title": "One",
"published": true
},
{
"title": "Two",
"published": false
}
]
}knap
{{ posts | where:("published", true) | map:"title" | join:", " }}md
One带类型的相等比较
json
{
"items": [
{
"value": 1
},
{
"value": "1"
}
]
}knap
{{ items | where:("value", "1") }}md
[{"value":"1"}]