gpt4 book ai didi

javascript - 如何使用 ng-repeat 显示 JSON 对象?

转载 作者:行者123 更新时间:2023-11-28 07:43:46 27 4
gpt4 key购买 nike

我正在使用 angularJS 创建一个 TreeView 菜单。有什么办法可以得到这个结果吗?我正在使用 Controller 来获取这个($scope.results)。我把 JSON 结果集和 Controller ..

<ul>
<li class="folder"><span>Pages</span>
<ul>
<li class="file"><span>page1</span></li>
<li class="file"><span>page2</span></li>
</ul>
</li>
<li class="folder"><span>TestSuites</span>
<ul>
<li class="file"><span>TestSuites1</span></li>
</ul>
</li>
</ul>

JSON..

{
"result": [
{
"@type": "d",
"@rid": "#-2:1",
"@version": 0,
"name": "pg3"
},
{
"@type": "d",
"@rid": "#-2:2",
"@version": 0,
"name": "pg3"
},
{
"@type": "d",
"@rid": "#-2:3",
"@version": 0,
"name": "pg3"
}
],
"notification": "Query executed in 0.023 sec. Returned 3 record(s)"
}

Controller ..

vController.controller('v-PagesController', [
'$scope',
'$q',
'vRESTService',
function($scope, $q, vRESTService) {

vRESTService.getPages().then(
function(results) {
$scope.results = results;
console.log(results);
//console.log(results);
// console.log(res);
//;;
}, function() {
console.log(Error);
});
}

]);

最佳答案

You can use $http.get 
Js file
$http.get('.json file ').success(function(data) {
$scope.name = name;
}

HTML File
<table> <tr ng-repeat= "x in y"> <td>{{x.Name }}</td> </tr> </table>

关于javascript - 如何使用 ng-repeat 显示 JSON 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27683990/

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