使用Angular js ng repeat指令过滤json对象
Filter json objects with Angular js ng-repeat directive
在我的angular js控制器中,我有一个包含大陆的json数组,大陆内部包含国家的数组
//CONTROLLER
app.controller('CountryController', function(){
this.continents =
[
{
name:'Africa',
countries:
[
{ name: 'Algeria', code:'DZ', operators:'3'},
{ name: 'Angola', code:'AO', operators:'1'},
{ name: 'Benin', code:'BJ', operators:'2'},
{ name: 'Burkina Faso', code:'BF', operators:'1'}
],
},
{
name:'AsiaPacific',
countries:
[
{ name: 'Afghanistan', code:'AF', operators:'4'},
{ name: 'Bahrain', code:'BH', operators:'2'}
],
}
];
});
在我看来,我想在按大洲排列的选项卡元素中显示国家,即我有选项卡来保存每个大洲的国家。例如,我有一个非洲选项卡,在这个选项卡中,我想显示非洲对象中的国家。我曾尝试使用"过滤器"在每个选项卡中只显示特定大陆的国家,但它不起作用,也没有任何显示。在检查元素时,代码似乎被注释了。这是我尝试使用Angular js完成的第一项任务,所以我仍在学习诀窍。
这就是我的观点
<div ng-app="countriessupported" class="container container_with_height">
<div ng-controller="CountryController as countryCtrl" id="myTabContent" class="tab-content hidden-xs">
<div class="tab-pane fade active in" id="africa">
<div class="col-md-12 countries_col-12" ng-repeat="continent in countryCtrl.continents.name | filter: 'Africa' ">
<a href="">
<div class="col-md-3 country_container" ng-repeat="country in continent.countries">
<div class="country_name">
{{ country.name }}
</div>
</div>
</a>
</div>
</div>
</div>
</div>
因此,我们的想法是用类col-md-3
在div中重复这些国家请问我怎样才能做到这一点?
试试这个html代码
<div ng-app="countriessupported" class="container container_with_height">
<div ng-controller="CountryController as countryCtrl" id="myTabContent" class="tab-content hidden-xs">
<div class="tab-pane fade active in" id="africa">
<div class="col-md-12 countries_col-12" ng-repeat="continent in countryCtrl.continents | filter: 'Africa' ">
<a href="">
<div class="col-md-3 country_container" ng-repeat="country in continent.countries">
<div class="country_name">{{ country.name }}</div>
</div>
</a>
</div>
</div>
</div>
</div>
让我知道这是否有帮助
尝试将第一个中继器更改为该ng-repeat="continent in countryCtrl.continents
而不是ng-repeat="continent in countryCtrl.continents.name
,过滤器将始终工作
相关文章:
- 在单击时过滤 JSON
- 如何用javascript过滤JSON数据
- 如何使用 AngularJs 过滤 JSON 数据
- 使用Angular js ng repeat指令过滤json对象
- 使用AngularJS过滤JSON数据
- 如何根据“架构”过滤 JSON 对象
- 使用 ng-repeat 过滤 JSON API
- 根据最小和最高价格过滤 JSON 数据
- 使用 javascript 过滤 JSON 数组
- 使用 Javascript 过滤 json 字符串
- 使用 JavaScript 过滤 Json
- 在angular js中过滤json或服务器中的数据
- 过滤 JSON 以获取 JavaScript 中的特定值
- 如何使用Ember.Select值来过滤JSON
- 无法仅通过名称过滤json数据
- 使用AngularJS过滤JSON数据,并使用智能表使用ng repeat登记
- 用javascript对象过滤json
- 如何通过按钮数据属性过滤JSON文件
- 如何使用关键字过滤JSON数组对象
- 通过javascript的字符串过滤json字段