gpt4 book ai didi

javascript - 错误: [ngRepeat:iexp] Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '(name,surname)in controller.students'

转载 作者:行者123 更新时间:2023-11-28 11:01:51 30 4
gpt4 key购买 nike

嗨,我正在尝试使用 ng-repeat 迭代 json 对象,当我迭代数组时,它工作正常,但使用 json 对象时,它失败了。

这是我的 JavaScript 代码:

 var appModule = angular.module('appModule',[]);
appModule.controller('appController',[function(){
this.students = {
"abc":"abc",
"xyz":"xyz",
"xyz":"xyz"
}
}]);

这是我的 html 代码:

<!DOCTYPE html>
<html ng-app="appModule">
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js"></script>
</head>
<body ng-controller="appController as controller">
<div ng-repeat="(firstName,lastName)in controller.students">
<span>Name:{{firstName}} Surname: {{lastName}}</span>
</div>
<script type="text/javascript" src="./app.js"></script>
</body>
</html>

最佳答案

可以尝试这样显示数据

<body ng-controller="appController as controller">
<div ng-repeat="student in controller.students">
<span>Name:{{student.firstName}} Surname: {{student.lastName}}</span>
</div>
</body>

关于javascript - 错误: [ngRepeat:iexp] Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '(name,surname)in controller.students' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39796854/

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