Javascript 如何在angularjs中显示我的JSON的特定部分
这里我有一个类似这样的JSON:Javascript 如何在angularjs中显示我的JSON的特定部分,javascript,angularjs,json,html,Javascript,Angularjs,Json,Html,这里我有一个类似这样的JSON: {"years":[ { "year_title":"94", "months":[...] } { "year_title":"95", "months":[...] } { "year_title":"96", "months":[...] } ]} 我用以下代码显示了它的数据: <div ng-repeat="year in event.years"> <h
{"years":[
{
"year_title":"94",
"months":[...]
}
{
"year_title":"95",
"months":[...]
}
{
"year_title":"96",
"months":[...]
}
]}
我用以下代码显示了它的数据:
<div ng-repeat="year in event.years">
<h1>{{year.year_title}}</h1>
<div ng-repeat="month in year.months">
<h3> {{month.month_title}} </h3>
</div>
</div>
{{年份.年份}
{{month.month{u title}}
因此,它显然向我展示了我的全部数据(所有年份、所有月份)。
但是,如果我只想显示特定年份的月份,该怎么办。!?
谢谢大家…使用您自己的过滤器,如:
<div ng-repeat="year in event.years | year">
<h1>{{year.year_title}}</h1>
<div ng-repeat="month in year.months">
<h3> {{month.month_title}} </h3>
</div>
{{年份.年份}
{{month.month{u title}}
var someApp=angular.module('someApp',[]);
someApp.filter('year',function(){
返回函数(输入,大写){
var out=[];
对于(变量i=0;i
})) 使用您自己的过滤器,如:
<div ng-repeat="year in event.years | year">
<h1>{{year.year_title}}</h1>
<div ng-repeat="month in year.months">
<h3> {{month.month_title}} </h3>
</div>
{{年份.年份}
{{month.month{u title}}
var someApp=angular.module('someApp',[]);
someApp.filter('year',function(){
返回函数(输入,大写){
var out=[];
对于(变量i=0;i
})) 试试angularjs内置的
过滤器
,根本不需要定制过滤器。您可以将94
更改为变量
ng-repeat="year in event.years | filter: {year_title: '94'}"
请参阅下面的演示:
角度模块(“应用程序”,[])
.controller(“myCtrl”,函数($scope){
$scope.event={
“年”:[{
“年份名称”:“94”,
“月份”:[{
月份标题:“一月”
}]
}, {
“年份名称”:“95”,
“月份”:[{
月份名称:“二月”
}]
}, {
“年份名称”:“96”,
“月份”:[{
月份标题:“12月”
}]
}]
};
});代码>
{{年份.年份}
{{month.month{u title}}
试试angularjs内置的过滤器,根本不需要定制过滤器。您可以将94
更改为变量
ng-repeat="year in event.years | filter: {year_title: '94'}"
请参阅下面的演示:
角度模块(“应用程序”,[])
.controller(“myCtrl”,函数($scope){
$scope.event={
“年”:[{
“年份名称”:“94”,
“月份”:[{
月份标题:“一月”
}]
}, {
“年份名称”:“95”,
“月份”:[{
月份名称:“二月”
}]
}, {
“年份名称”:“96”,
“月份”:[{
月份标题:“12月”
}]
}]
};
});代码>
{{年份.年份}
{{month.month{u title}}
你可以使用angularjs提供的过滤器:我是说我的数组的一个特殊部分你可以使用angularjs提供的过滤器:我是说我的数组的一个特殊部分如果(输入[I].year==95)它表示未解析的变量year。我已经更改了代码,现在试试,或者提供JSFIDLE我会帮助你。如果(输入[I].year==95)上面写的是未解决的变量年。我已经修改了代码,现在就试试,或者提供JSFIDLE,我会帮你的。真棒的工作人员。到目前为止你到哪里去了!?我吃谷歌是为了找到解决办法:D.了不起的职业杀手。到目前为止你到哪里去了!?我吃谷歌是为了找到解决方案:D。