2013-04-10 7 views
3

저는 리튬 사용자 정의 구성 요소를 사용하여 대부분의 블로그 기사를 작성한 사용자 목록을 작성하고 있습니다. 블로그 기사를 작성한 사용자 목록을 작성한 다음 나머지 사용자가 각 사용자가 작성한 블로그 기사 수를 얻으려고 전화를했습니다. Lithium/Freemarker에서 중복 제거

<#assign authors = rest("blogs/id/audiofile/posts")> 

<#list authors.node_message_context.message.author as t> 
<#assign count = rest("${[email protected]}/posts/style/blog/count")> 
<#assign orderedCount = count.value> 
<#list orderedCount as c> 
<ul> 
<li>Blog posts ${c} userid ${[email protected]} 
</ul> 
</#list> 
</#list> 

는 어떻게이 목록에 중복 저자를 제거합니까있다

Blog posts 4 userid /users/id/2477 

Blog posts 4 userid /users/id/2477 

Blog posts 4 userid /users/id/2477 

내 질문의 출력을 제공합니다?

답변

0

자주 묻는 질문 http://freemarker.org/docs/app_faq.html#faq_modify_seq_and_map 왜 이것이 까다로운지를 설명합니다. 기본적으로 그것은 당신을 위해 일을하기 위해 편안한 인터페이스를 수정하기위한 호출

<#assign authors = rest("blogs/id/audiofile/uniquauthors")> 

는 새로운 편안한 인터페이스에 대한 예가 될 것이다 다음 작업은 서버 측에서 수행된다.

2

@ 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 % 확인 안된이지만, 위의 코드를 사용하여 내가 선택한 방법이 분명 해졌을 때 ...