简体   繁体   English

使用ng-repeat访问AngularJS中的JSON

[英]Accessing a JSON in AngularJS using ng-repeat

<table class="table table-striped" >
    <thead>
        <tr>
            <th>Number</th>
            <th>Zeroes</th>

        </tr>
    </thead>
    <tbody ng-controller="ViewData as viewAll">
        <tr ng-repeat="pop in viewAll.number">
            <td>{{pop.number}}</td>
            <td>{{pop.zeroes}}</td>

    </tbody>
</table>

I have this table and I'm trying to get data to be outputted in it. 我有这张桌子,我正在尝试获取要在其中输出的数据。

app.controller('ViewData', ['$http', '$scope',

    function($http,$scope) {

        $scope.viewAll = this;

        $http.get('/someurl').success(function(data) {

            $scope.viewAll.number = data;
        });
    }]);

This my controller getting the data. 这是我的控制器获取数据。

 {"number": {
"4": {
    "zeroes": "5"
},
"5": {
    "zeroes": "6"
},
"10": {
    "zeroes": "7"
}}

And this is the data that /someurl is giving out to me.. Is there any way I can be able to handle this so I can be able to show it outside the table. 这就是/ someurl提供给我的数据。.有什么办法可以处理这个问题,以便可以在表外显示。 Thanks in advance for any kind of help given! 在此先感谢您提供的任何帮助!

try: 尝试:

<table class="table table-striped" >
    <thead>
        <tr>
            <th>Number</th>
            <th>Zeroes</th>

        </tr>
    </thead>
    <tbody ng-controller="ViewData as viewAll">
        <tr ng-repeat="{key, value} in viewAll.number">
            <td>{{key}}</td>
            <td>{{value.zeroes}}</td>
    </tbody>
</table>

app.controller('ViewData', ['$http', '$scope',

    function($http,$scope) {

        var self = this;

        $http.get('/someurl').success(function(data) {

            self.number = data;
        });
    }]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM