我正在尝试显示来自我的JSON对象的数据,我的对象在2个图像中如下
在数据中,我有c_name
,max_slots
和数组slots
,我有base_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>
答案 0 :(得分:2)
您无法在div标签中显示图片,请使用 <img>
代替
<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>
答案 1 :(得分:0)
由于base_image
位于内部数组中,您必须在ng-repeat
responseData
<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>
答案 2 :(得分:0)
{{data.base_image}}
无法访问,因为它位于嵌套的slots
数组中,因此为了引用base_image
,您还必须遍历插槽。试试这里给出的东西: