[英]Json files are not displaying data
我在尝试读取Json文件(与html页面位于同一目录中)时遇到了这个问题,但是每当我运行该应用程序时,都会显示此问题。 (这是我的html页面-后面的代码)
.jSON文件-
[
{ "_id":"1", "description":"Samsung Note 4", "price":899, "image": "samsung-note4.png", "platform":"Android Jellybean" },
{ "_id":"2", "description":"iPhone 6", "price":1028, "image": "iphone6.png", "platform":"iOS 8" },
{"_id": "3","description": "HTC One (M8)","price": 768,"image": "htc-one.png","platform": "Windows 8"}
]
这是我的JS文件-
App.controller('ProductController', function($scope, $http){
$http.get('products.json')
.then(function(res){
$scope.products = res.data;
});
$scope.selectProduct = function (id) {
$scope.product = _.where($scope.products, {_id: id})[0];
}
});
我不知道为什么无法在jSON文件中获取数据。 有什么可能的原因吗?
此部分需要更正:
.then(function(res){
$scope.products = res;
});
由于res是解析的JSON数据。 无需使用res.data
在ng-repeat的'product'中尝试小写的p
<li ng-repeat="product in products" >
{{ product.image }}
在您的控制器中,尝试以下操作:
.when(function(data){
$scope.products = data;
});
响应对象具有以下属性:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.