gpt4 book ai didi

javascript - Angular 语法错误 : Unexpected token }

转载 作者:行者123 更新时间:2023-12-03 09:45:34 25 4
gpt4 key购买 nike

我花了一个小时尝试调试这个,但我完全不知道为什么这是错误的。

我一直在尝试根据从 json 文件检索的数据使用 Angular 在页面上显示一行图像。然而,Angular 一直给我这个错误:

SyntaxError: Unexpected token }
at Object.parse (native)
at fromJson (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:1076:14)
at defaultHttpResponseTransform (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:8651:16)
at http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:8736:12
at forEach (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:327:20)
at transformData (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:8735:3)
at transformResponse (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:9465:23)
at processQueue (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:13293:27)
at http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:13309:27
at Scope.$get.Scope.$eval (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:14548:28)

这是我的代码

HTML:

<div id="officersPage" class="row" ng-app="officers" ng-controller="officerCtrl">
<div id="officerModals" class="col-md-4" ng-repeat="officersOne in officersGroup">
<div class="officerPics" ng-repeat="officer in officersOne">
<%= image_tag('logo.png', :id=>"{{officer.id}}", size: '140x140', :class=>"img-responsive, img-thumbnail") %>

</div>
</div>
<div id="moreDetails" class="col-md-4">
</div>
</div>

Angular 代码:

# Contains the Angular code for the officer page -> will generate all the pictures and modals based on info through JSON file
app = angular.module('officers', [])

app.controller 'officerCtrl', [
'$scope'
'$http'
($scope, $http) ->
$http.get('./officers.json').success (data) ->
console.log(data)
$scope.officersGroup = data
console.log($scope.officersGroup)
return
]

任何帮助都会很棒!

编辑:JSON 文件示例如下:

{
"officers": [
{
"name": "Matt Zhang",
"role": "Webmaster",
"class": "2018",
"id" : "matt"
}
]
}

最佳答案

只是一个猜测,当你分配时:

$scope.officersGroup = data 

不应该吗?

$scope.officersGroup = data.officers

这是代码中的第一次迭代。那么在第二次迭代中,您是否使用 ng-repeat 来迭代对象的属性?如果是这样,我认为这不是最好的方法。

<div class="officerPics" ng-repeat="officer in officersOne">

干杯

关于javascript - Angular 语法错误 : Unexpected token },我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31043269/

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