Javascript 无法显示来自json对象的图像
我试图显示来自JSON对象的数据,我的对象如下图2所示 在数据中,我有Javascript 无法显示来自json对象的图像,javascript,html,angularjs,json,Javascript,Html,Angularjs,Json,我试图显示来自JSON对象的数据,我的对象如下图2所示 在数据中,我有c\u name,max\u slots和一个数组slots,在该数组中我有base\u image 我无法获取要在HTML中显示的基本图像数组 这是我当前的HTML打印输出 这是我的JavaScript $scope.GetData = function () { $http({ url: "http://www.ccuktech.co.uk/ccuploader/c
c\u name
,max\u slots
和一个数组slots
,在该数组中我有base\u image
我无法获取要在HTML中显示的基本图像数组
这是我当前的HTML打印输出
这是我的JavaScript
$scope.GetData = function () {
$http({
url: "http://www.ccuktech.co.uk/ccuploader/campaigns/getCampaign",
method: "POST",
date: {},
headers: {'Content-Type': 'application/json'}
}).then(function (data) {
// success
console.log('you have received the data ');
console.log(data);
$scope.responseData = data.data;
}, function (response) {
// failed
console.log('failed getting campaigns goo back to log in page.');
console.log(response);
});
};
$scope.GetData();
和HTML
<div ng-repeat="data in responseData">
<h2>name</h2>:
{{data.c_name}}
<h2>max slots</h2>:
{{data.max_slots}}
<h2>image</h2>:
{{data.base_image}}
</div>
姓名:
{{data.c_name}
最大插槽数:
{{data.max_slots}
图片:
{{data.base_image}
您不能仅在div标记中显示图像,请使用由于
base\u图像
位于内部数组中,因此必须在responseData的ng repeat
中循环该数组
<div ng-repeat="data in responseData">
<h2>name</h2>:
{{data.c_name}}
<h2>max slots</h2>:
{{data.max_slots}}
<h2>image</h2>:
<img ng-src="{{data.base_image}}"></img>
</div>
姓名:
{{data.c_name}
最大插槽数:
{{data.max_slots}
图片:
无法访问,因为它位于嵌套的插槽
数组中,因此为了引用基本图像
,您还必须遍历插槽。尝试下面给出的方法:
兄弟,我们现在正在尝试使用jade,所以只要转换,然后就会再次接受答案。谢谢你,伙计。
<div ng-repeat="data in responseData">
<h2>name</h2>:
{{data.c_name}}
<h2>max slots</h2>:
{{data.max_slots}}
<h2>image</h2>:
<div ng-repeat="slot in slots">
<img src={slot.base_image} />
</div>
</div>
{{data.base_image}}