【发布时间】:2017-02-02 16:20:01
【问题描述】:
我正在 ionic /angularjs 中创建应用程序。
控制器从 URL 中获取 JSON 格式的数据,并在 div 元素中显示唯一的图像。我想让这些图片被点击,然后根据来自JSON数据的offer_name显示数据。
例如:假设我显示亚马逊的图像(在后台 offer_name 是亚马逊(有 10 条记录))。当用户点击它时,它会显示与亚马逊相关的所有记录。
希望你明白我的意思,但不包括数据库;它仅适用于 JSON 数据。
另外,如何在ng-repeat中检查检查当前值?
这是我的代码:
.controller('menuCtrl', function($scope,$http) {
$http.get("http://tools.vcommission.com/api/coupons.php?apikey=e159f64e3dd49fddc3bb21dcda70f10c6670ea91aac30c7cb1d4ed37b20c45b8").then(function (response) {
$scope.myData = response.data;
/* $scope.stack=[];
angular.forEach($scope.myData, function(item){
$scope.stack =item.store_image;
var uni_img=[];
for(var i=0 ; i< $scope.stack.length;i++)
{
if(uni_img.indexOf($scope.stack[i] == -1))
uni_img.push($scope.stack[i]);
}
console.log(uni_img);
})*/
});
$scope.dealopen = function($a){
for (var i=0;i<$scope.myData.length;i++)
{
//console.log($scope.data[i].name);
$link=$scope.data[i].offer_name;
if ($link==$a)
{
$window.open($link,"_self","location=yes");
console.log($a);
}
}
}
})
HTML
<div class="item col-sm-2 col-sm-3 col-md-2 " ng-repeat="da in myData | unique: 'store_image'" >
<div class="thumbnail">
<img class="thumbnail img-responsive " ng-src="{{ da.store_image}}"
/>
<div class="caption">
<b class="group inner list-group-item-heading center-block">
{{da.offer_name | limitTo: 12 }} Deals</b>
<a class="item item-text-wrap" ng-href="#/Deals/{{da.offer_name}}">View Deal</a>
</div>
</div>
</div>
这是输出:
.
【问题讨论】:
-
你能提供一个 JSON 文件的样本吗?
标签: javascript angularjs json angularjs-ng-repeat ng-repeat