dimaip/groupby

FlowQuery 的 groupBy 操作,用于根据 EEL 区分符对数组进行分组

安装数: 6,250

依赖: 0

建议者: 0

安全: 0

星星: 6

关注者: 4

分支: 4

开放问题: 1

类型:neos-package

6.0 2022-09-27 14:13 UTC

This package is auto-updated.

Last update: 2024-08-28 14:12:24 UTC


README

FlowQuery 的 groupBy 操作,用于根据 EEL 区分符对数组进行分组

曾经,我有一份人员节点列表,需要根据首字母进行分组。所以我决定应该有一个通用的方式,可以根据 EEL 表达式将节点数组分组到子组中... 现在它就在这里!

简化版

安装: composer require dimaip/groupby

使用

groupedNodesByFirstLetterOfLastName = ${q(nodes).groupBy('String.substring(node.properties.lastName, 0, 1)')}

完整示例

一旦你对节点进行了分组,你可以以任何你想要的方式渲染它们:使用 Fluid(哇哦!)或使用 Fusion(太好了!)。

prototype(Name.Space:GroupedList) < prototype(TYPO3.TypoScript:Collection) {
	@process.tmpl = ${'<div class="grouped-list">' + value + '</div>'}
	@context.nodes = ${q(site).find('[instanceof Name.Space:Person]')}
	collection = ${nodes.groupBy('String.substring(node.properties.lastName, 0, 1)')}
	itemName = 'nodes'
	itemKey = 'firstLetter'
	itemRenderer = TYPO3.TypoScript:Collection {
		@process.tmpl = ${'<div><h2>' + firstLetter + '</h2><ul>' + value + '</ul></div>'}
		collection = ${nodes}
		itemName = 'node'
		itemRenderer = ${'<li>' + node.properties.firstName + ' ' + node.properties.lastName + '</li>'}
	}
}

以类似的方式,你可以根据非常复杂的 EEL 表达式对节点进行分组,让你的想象力飞翔!

致谢

初始开发由 Stefan Johänntgen 赞助