gpt4 book ai didi

javascript - 拆分一个 json 并使用 ng-repeat angular 指令显示它

转载 作者:行者123 更新时间:2023-11-29 21:32:09 25 4
gpt4 key购买 nike

如何查看拆分的 json 字符串的 Key: value 列表?

function MyCtrl($scope) {

var jsonString='{"prop":"1, 2, 3, 4, 5, 6", "prop": "lol, asd, lidfj", "prop": "asd, test!!!"}';
$scope.evalled=$scope.$eval(jsonString);

$scope.fromJsoned=angular.fromJson(jsonString);

$scope.ljson = JSON.parse(jsonString);
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
<div ng-controller="MyCtrl">
<p>JSON.parse:</p>
<ul>
<li ng-repeat="son in ljson">Key: {{son.key }}, Value: {{son}}</li>
</ul>
</div>
</div>

在这个例子中,目标是显示:

 - Key: prop, Value: 1, 2, 3, 4, 5, 6
- Key: prop, Value: lol, asd, lidfj
- Key: prop, Value: asd, test!!!

最佳答案

您可以使用 ng-repeat="(key, value) in data"。那么你的代码就变成了

<li ng-repeat="(key, value) in ljson">Key: {{key }}, Value: {{value}}</li>

关于javascript - 拆分一个 json 并使用 ng-repeat angular 指令显示它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35879389/

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