gpt4 book ai didi

javascript - 使用 angularjs 无法从 json 文件获取数据

转载 作者:行者123 更新时间:2023-11-28 00:00:56 25 4
gpt4 key购买 nike

这是我的 HTML 文件和 JS 文件我没有从 JSON 文件到 html 文件获取任何数据下面我有 HTML 文件和 JS 文件:

<!Doctype html>
<html ng-app>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script type="text/javascript">
alert("c");
function imagecontroller($http,$scope){
alert("cd");
$http.get('ytdata.json').success(function(ytdata) {
alert("cdscdsc");
$scope.data = ytdata;
});
}
</script>
<style type="text/css">
li{list-style:none;float:left;padding:20px;}
a{text-decoration:none;}
</style>
</head>
<body>
<div ng-controller="imagecontroller">
<ul>
<li ng-repeat="datum in data">
<a>
<img ng-src="{{datum.thumbUrl}}"/>
<br />Id : {{datum.id}}
<br />Purchase : {{datum.Purchase}}
</a>
</li>
</ul>
</div>
</body>
</html>

这是我的 json 文件:

[
{
"id":"mobile.jpg",
"thumbUrl":"image url",
"Purchase":20000
},
{
"id":"pendrive.jpg",
"thumbUrl":"image url",
"Purchase":400
},
{
"id":"laptop.jpg",
"thumbUrl":"image url",
"Purchase":3833
}

]

请给我这个程序的输出

提前致谢

最佳答案

Here is a working plunker of what you are trying to do :

Controller

app.controller('MainCtrl', function($scope, $http) {
$scope.data = null;
$http.get("data.json").success(function (data) {
$scope.data = data;
});
});

查看

<body ng-controller="MainCtrl">
<ul>
<li ng-repeat="datum in data">
<a>
<img ng-src="{{datum.thumbUrl}}" />
<br />Id : {{datum.id}}
<br />Purchase : {{datum.Purchase}}
</a>
</li>
</ul>
</body>

关于javascript - 使用 angularjs 无法从 json 文件获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31816187/

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