0

我试图以 'cols' 为起点重复 ng-repeat。但是在尝试使用此 JSON 时出现错误

{
"cols":["id","name","type"],
"rows":[
    ["284","JAMES DEAN","Employee"],
    ["243","Brian J Adamms","Employee"],
    ["237","Test Account","Brokerage Account"],
    ["241","Robert Borkman","guest"]
  ]
}

错误似乎在 angularJS 文件中,但我确定问题出在其他地方。

Error: a.push is not a function 
W@http://127.0.0.1/js/lib/angular.min.js:10 
g@http://127.0.0.1/js/lib/angular-resource.min.js:7 
u/</g[b]/</<@http://127.0.0.1/js/lib/angular-resource.min.js:8 
o@http://127.0.0.1/js/lib/angular.min.js:7 
u/</g[b]/<@http://127.0.0.1/js/lib/angular-resource.min.js:8 
Rc/e/g.promise.then/i@http://127.0.0.1/js/lib/angular.min.js:79 
Rc/e/g.promise.then/i@http://127.0.0.1/js/lib/angular.min.js:79 
Rc/f/<.then/<@http://127.0.0.1/js/lib/angular.min.js:79 
e.prototype.$eval@http://127.0.0.1/js/lib/angular.min.js:91 
e.prototype.$digest@http://127.0.0.1/js/lib/angular.min.js:89 
e.prototype.$apply@http://127.0.0.1/js/lib/angular.min.js:91 
f@http://127.0.0.1/js/lib/angular.min.js:100 
B@http://127.0.0.1/js/lib/angular.min.js:103 
ad/</p.onreadystatechange@http://127.0.0.1/js/lib/angular.min.js:105

这是一个“plunker”示例——运行控制台——你会看到我得到的同样的错误——并且 JSON 显示为一个空数组。

http://plnkr.co/edit/QgNkvsOIVzrpUp5pP02p?p=preview

谢谢大家的帮助

4

2 回答 2

1

我能够解决您面临的问题,请参阅以下代码

 <html ng-app="myapp" >

  <head lang="en">
    <meta charset="utf-8">
    <title>Custom Plunker</title>

    <script src="Scripts/Angular.js"></script>
  </head>

  <body >
<div ng-controller="TestCtrl" >
   <div ng-repeat="data in data.cols">
       {{data}}
   </div>
</div>
        <script>
            var myapp = angular.module('myapp', []);



            function TestCtrl($scope, $http,$timeout) {
                $scope.data = {
                    "cols": ["id", "name", "type"],
                    "rows": [
                        ["284", "JAMES DEAN", "Employee"],
                        ["243", "Brian J Adamms", "Employee"],
                        ["237", "Test Account", "Brokerage Account"],
                        ["241", "Robert Borkman", "guest"]
                    ]
                };


            }


  </script>     
  </body>



</html>
于 2013-06-12T18:05:38.317 回答
1

I don't think the error is in angular source, and it will handle that JSON just fine: http://plnkr.co/edit/knJQ0S?p=preview

于 2013-06-12T18:08:28.287 回答