gpt4 book ai didi

javascript - 在某些条件下使用 ng-repeat 显示 JSON

转载 作者:行者123 更新时间:2023-11-28 03:55:40 25 4
gpt4 key购买 nike

我有一个使用 $http() 获取的 JSON 文件。它是这样的:

[{
"sno": "4",
"eventname": "cricket",
"event-type": "sports",
"A-team": "mme",
"B-team": "eee",
"Gender": "male",
"time": "2017-11-24 00:00:00",
"isresult": "1",
"result": "[{\"a\":\"121/5\",\"b\":\"122/4\"}]",
"match-type": "semi",
"venue": "downs"
},
{
"sno": "2",
"eventname": "cricket",
"event-type": "sports",
"A-team": "cse",
"B-team": "mme",
"Gender": "female",
"time": "2017-11-17 00:00:00",
"isresult": "0",
"result": "winner team-a",
"match-type": "league",
"venue": "tsg"
}]

我需要使用 ng-repeat 显示此内容,但仅在其属性( bool 值)isresult 时显示 {{item.result}}0。如果isresult === 1并且event-type=='sports',我就有了需要ng-repeat的数组。

我做了这样的事情:

<th ng-if="item.isresult === 1 && item[event-type] === 'sports'">
<div ng-repeat="i in item.result">
{{i.a}}<br>{{i.b}}
</div>
</th>

此外,如果event-type === 'athletics',我会在一个数组中得到结果,看起来像[{"1":"Xjdjd"}, {"2":"Jxjxj"}, {"3":"Dhdj"}]

我该怎么做?

最佳答案

angular.module('app', []).controller('ctrl', function($scope) {
$scope.data = [{
"event-type": "sports",
"isresult": "1",
"result": [{
"a": "121/5",
"b": "122/4"
}],
},
{
"event-type": "sports",
"isresult": "0",
"result": "winner team-a",
},
{
"event-type": "athletics",
"isresult": "1",
"result": [{
'1': 'Xjdjd'
}, {
'2': 'Jxjxj'
}, {
'3': 'Dhdj'
}],
}
]
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app='app' ng-controller='ctrl'>
<div ng-repeat='item in data'>
<div ng-if="item.isresult == 1 && item['event-type'] === 'sports'">
<div ng-repeat="i in item.result">
{{i.a}}<br>{{i.b}}
</div>
</div>
<div ng-if="item.isresult == 0">
{{item.result}}
</div>
<div ng-if="item['event-type'] === 'athletics'">
<div ng-repeat="i in item.result">
<div ng-repeat="(key, value) in i">
{{key}}:{{value}}
</div>
</div>
</div>
<hr ng-if='!$last'>
</div>
</div>

关于javascript - 在某些条件下使用 ng-repeat 显示 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47567262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com