在geonetwork 3.6主页中,我想选择显示哪些元数据类别。 Geonetwork使用AngularJs(我不熟悉)进行多面搜索来选择显示的类别。默认情况下,显示所有可用类别。
代码如下:
<div class="row">
<span data-ng-repeat="(key, facet) in searchInfo.facet['category']"
class="col-xs-12 col-sm-6 col-md-4 chips-card">
<a href="#/search?facet.q=category%2F{{facet['@name']}}">
<img class="pull-left img-thumbnail" src="http://localhost:8080/geonetwork/images/harvesting/odnature.png" alt="thumbnail image"></img>
</a>
<a class="pull-left clearfix"
title="{{facet['@label']}}">
<span class="badge-text pull-left">
<span class="gn-icon-label">{{facet['@label']}}</span>
</span>
</a>
</span>
</div>
我不需要选择所有类别,而是只选择其中几个类别。我尝试通过更改ng-repeat元素来进行过滤,例如:
<span data-ng-repeat="(key, facet) in searchInfo.facet['category'] == 'some_category'"
但没有结果。有没有一种方法可以轻松选择要显示的元素?
答案 0 :(得分:0)
AngularJS具有ngRepeat
的{{3}}语法:
<span data-ng-repeat="(key, facet) in searchInfo.facet['category'] | filter:'some_category'" ...>
如果要过滤多个字符串,最好使用谓词函数:
<span data-ng-repeat="(key, facet) in searchInfo.facet['category'] | filter:catSubset" ...>
在控制器中定义谓词功能:
$scope.catSubset = function(value, index, array) {
if(value == "some_category" || value == "some_other_category") {
return true;
}
}
Internet Explorer(不带polyfill)不支持此功能,但更易于读取/编写:
var selectedCategories = [
"some_category",
"some_other_category"
];
$scope.catSubset = function(value, index, array) {
if(selectedCategories.includes(value)) {
return true;
}
}
答案 1 :(得分:0)
由于我需要的类别数量非常有限,因此我更改了策略并对其进行了编码,而不是使用过滤器选项。 如果需要很多类别,这不是一个有效的解决方案,但就我而言,这是可以接受的。我是这样编码的:
<div class="col-sm-12 col-md-12" data-ng-show="browse !== ''"> <!-- set width of facet box on main page -->
<h3>
<div class="row"> <!-- box containing the different topics -->
<!-- First category -->
<div class="col-xs-12 col-sm-6 col-md-4 chips-card text-center">
<a href="#/search?facet.q=keyword%2FMarine Spatial Plan%26type%2Fdataset&resultType=details">
<img class="img-thumbnail" src="http://localhost:8080/geonetwork/images/harvesting/belgica-image.jpeg" alt="thumbnail image"></img>
<p>Marine Spatial Plan</p>
</a>
</div>
<!-- Second category -->
<div
class="col-xs-12 col-sm-6 col-md-4 chips-card text-center">
<a href="#/search?facet.q=keyword%2FMarine Strategy Framework Directive%26type%2Fdataset&resultType=details">
<img class="img-thumbnail" src="http://localhost:8080/geonetwork/images/harvesting/MSFD-logo.jpeg" alt="thumbnail image"></img>
<p class="text-center">Marine Strategy Framework Directive</p>
</a>
</div>
以此类推。