我正在使用ng-repeat来构建一个使用jQuery和TB的手风琴.出于某种原因,这在硬编码时工作正常,但在ng-repeat指令内部无法触发.
我当时认为这个问题来自jQuery,而不是事后加载的绑定元素.因此,我认为不是在页面加载时加载脚本,而是在返回数据时在.success上加载函数会更好.不幸的是,我无法弄清楚如何使这项工作.
测试页面:http://staging.converge.io/test-json
控制器:
function FetchCtrl($scope, $http, $templateCache) { $scope.method = 'GET'; $scope.url = 'https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=http://www.web.com&key=AIzaSyA5_ykqZChHFiUEc6ztklj9z8i6V6g3rdc'; $scope.key = 'AIzaSyA5_ykqZChHFiUEc6ztklj9z8i6V6g3rdc'; $scope.strategy = 'mobile'; $scope.fetch = function() { $scope.code = null; $scope.response = null; $http({method: $scope.method, url: $scope.url + '&strategy=' + $scope.strategy, cache: $templateCache}). success(function(data, status) { $scope.status = status; $scope.data = data; }). error(function(data, status) { $scope.data = data || "Request failed"; $scope.status = status; }); }; $scope.updateModel = function(method, url) { $scope.method = method; $scope.url = url; }; }
HTML:
Impact score: {{ruleResult.ruleImpact*10 | number:0 | orderBy:ruleImpact}}
jQuery (在ng-repeat之外工作)
$('.panel-heading').on('click', function() { var $target = $(this).next('.panel-collapse'); if ($target.hasClass('collapse')) { $target.collapse('show'); }else{ $target.collapse('hide'); } });
谢谢你的帮助!