如何使用 Structr 遍历密码集合中的元素?
How do I use Structr to iterate through elements in a cypher collection?
我正在试用 Structr,它看起来不错,但我 运行 遇到了一个问题,我想循环返回的集合并为每个项目输出一个 html 元素在里面。这有点复杂,因为在我这样做之前我还需要在集合上使用 merge_unique,因为旧版本的 neo4j Structr 在可选匹配和 collect(distinct n).[= 的组合上使用扼流圈11=]
这是我在 Structr 的密码查询面板中提出的请求:
MATCH (c:Country) WHERE c.code = 'US'
Optional match (c)<-[:THING_IN]-(t:Thing)-[:THING_BELONGS_TO]-(p:Project)
optional match (p)<-[:SPONSORS]-(sp)
where p.status = "ACTIVE"
with c, collect(distinct p) as projects, collect(sp.name) as sponsors
RETURN {
name:c.name,
code:c.code,
open_projects:size(filter(x IN projects WHERE x.status = "ACTIVE")),
closed_projects:size(filter(x IN projects WHERE x.status <> "ACTIVE")),
all_projects:size(projects),
sponsors:sponsors
}
因此,"sponsors" 作为项目发起人的所有名称的非唯一集合返回。如果赞助商作为对象返回,它会循环遍历赞助商,并显示 ${sponsor.name}(在使用赞助商创建数据绑定后 = merge_unique(data.sponsors),但是我不能只显示字符串变量集合中的每个赞助商。
我不确定我是否解释得很好,但如果您使用过 Structr,我想这是您 运行 遇到的问题。如果你能给我指出正确的方向,在此先感谢。
使用以下测试数据重现您的查询,我得到了相同的结果(赞助商名称的非不同列表)。
如果我在 Cypher 声明中添加 distinct
,它 return 是赞助商的独特集合:
[...]
with c, collect(distinct p) as projects, collect(distinct(sp.name)) as sponsors
[...]
请注意,sponsors
中的集合已经是一个字符串数组,因此您不能轻易使用 Structr 转发器(有一种方法,但它更复杂)。
要直接使用 Structr 的数据绑定,将查询修改为 return 个对象 (sp.name
=> sp
) 并创建一个带有函数查询的嵌套转发器(在我的示例绑定中到 元素:
[...]
with c, collect(distinct p) as projects, collect(distinct(sp)) as sponsors
[...]
我正在试用 Structr,它看起来不错,但我 运行 遇到了一个问题,我想循环返回的集合并为每个项目输出一个 html 元素在里面。这有点复杂,因为在我这样做之前我还需要在集合上使用 merge_unique,因为旧版本的 neo4j Structr 在可选匹配和 collect(distinct n).[= 的组合上使用扼流圈11=]
这是我在 Structr 的密码查询面板中提出的请求:
MATCH (c:Country) WHERE c.code = 'US'
Optional match (c)<-[:THING_IN]-(t:Thing)-[:THING_BELONGS_TO]-(p:Project)
optional match (p)<-[:SPONSORS]-(sp)
where p.status = "ACTIVE"
with c, collect(distinct p) as projects, collect(sp.name) as sponsors
RETURN {
name:c.name,
code:c.code,
open_projects:size(filter(x IN projects WHERE x.status = "ACTIVE")),
closed_projects:size(filter(x IN projects WHERE x.status <> "ACTIVE")),
all_projects:size(projects),
sponsors:sponsors
}
因此,"sponsors" 作为项目发起人的所有名称的非唯一集合返回。如果赞助商作为对象返回,它会循环遍历赞助商,并显示 ${sponsor.name}(在使用赞助商创建数据绑定后 = merge_unique(data.sponsors),但是我不能只显示字符串变量集合中的每个赞助商。
我不确定我是否解释得很好,但如果您使用过 Structr,我想这是您 运行 遇到的问题。如果你能给我指出正确的方向,在此先感谢。
使用以下测试数据重现您的查询,我得到了相同的结果(赞助商名称的非不同列表)。
如果我在 Cypher 声明中添加 distinct
,它 return 是赞助商的独特集合:
[...]
with c, collect(distinct p) as projects, collect(distinct(sp.name)) as sponsors
[...]
请注意,sponsors
中的集合已经是一个字符串数组,因此您不能轻易使用 Structr 转发器(有一种方法,但它更复杂)。
要直接使用 Structr 的数据绑定,将查询修改为 return 个对象 (sp.name
=> sp
) 并创建一个带有函数查询的嵌套转发器(在我的示例绑定中到 元素:
[...]
with c, collect(distinct p) as projects, collect(distinct(sp)) as sponsors
[...]