红联Linux门户
Linux帮助

在XWiki中的#livetable宏中自定义过滤条件

发布时间:2014-10-27 15:03:45来源:linux网站作者:linux人

下面这段文字是在#livetable的在线文档中的示例描述:http://extensions.xwiki.org/xwiki/bin/view/Extension/Livetable+Macro#HFilterorganizationsbydomain


Filter organizations by domain
The organization class in the example below has two properties: an org_name of type String and an org_domain of type StaticList. The organization domain can have values like Software or Hardware, which will be used in the live table as filter options.

#set($columns = ["org_name", "org_domain"])
#set($columnsProperties = {
"org_name" : { "type" : "text" , "size" : 20, "link" : "view"},
"org_domain" : { "type" : "list", "class": "MySpace.OrganizationClass"}
})

#set($options = {
"resultPage":"MySpace.ListOrganizationJSON",
"translationPrefix" : "",
"rowCount": 10
})
#livetable("organization_directory" $columns $columnsProperties $options)
The content of MySpace.ListOrganizationJSON (using syntax 2.0):

{{include document="XWiki.LiveTableResultsMacros" /}}
{{velocity}}
#gridresultwithfilter("MySpace.OrganizationClass" $request.collist.split(",") "" " and doc.name<>'OrganizationSheet' and doc.name<>'OrganizationTemplate'")
{{/velocity}}


此示例感觉写得有点文不对题,实际上通常我们使用过滤时会根据实际对象(如例子中的OrganizationClass的文档中的对象)的属性进行过滤,比如现在有类:XWiki.DanJuSummaryClass,有属性version(字符串),需要表格展示所有version属性值为V7.0的文档出来怎么写过滤条件呢?


参考如下示例,在新建的页面中(如上面例子中的MySpace.ListOrganizationJSON页面)

{{include document="XWiki.LiveTableResultsMacros" /}}
{{velocity}}
#gridresultwithfilter("XWiki.DanJuSummaryClass" $request.collist.split(",") " ,StringProperty as sp" " and sp.name='version' and sp.value='V7.0' and obj.id=sp.id")
{{/velocity}}


SringProperty 是XWIKI中的所有字符串属性存储实体,最后一个条件obj.id=sp.id很重要,相当于SQL中的关联条件,没有这个条件过滤逻辑是不正确的,则结果也不正确。