@Wolfgang Fahl希望我們可以修改Lithium REST API =)!
不幸的是,這是不是這樣的,所以我們必須對付我們得到什麼,也可以做這樣的事情:
<#-- this variable we need to store unique author ids -->
<#assign authorids = [] />
<#-- I'd use API v2 here, think for such stuff it's more powerful than v1 -->
<#assign query = 'SELECT author FROM messages WHERE conversation.style = "blog" AND board.id = "audiofiles"'?url />
<#assign response = rest("2.0", "https://stackoverflow.com/search?q=" + query) />
<#-- the response object will contain a list of blog post authors,
we loop trough them to get uniqe ids of every user that has written
a blog post, we need them later -->
<#list response.data.items as author>
<#-- make sure each author just gets added once -->
<#if !authorids?seq_contains(author.id)>
<#assign authorids = authorids + [author.id] />
</#if>
</#list>
<#-- now we loop trough the unique author ids and ask for the amount of
blog posts they have written -->
<ul>
<#list authorids as id>
<#assign query = 'SELECT count(*) FROM messages WHERE author.id = id AND board.id = "audiofiles"'?url />
<#assign response = rest("2.0", "https://stackoverflow.com/search?q=" + query) />
<li>User with ID ${id} has written ${response.data.count} blog posts</li>
</#list>
</ul>
代碼是未經測試,所以不是100%肯定,如果它的工作原理,但我希望我選擇的方法通過上面的代碼變得清晰...