25
我想從我的應用程序中刪除jquery ..但我想在angularjs中替換$ .each ... 如何循環dom元素? 在這裏,我已經加了我的代碼..我想將其轉換成angularjs從jQuery的jQuery的每個angularjs的替代方法是什麼?
app.directive('activeu', function($location) {
return function ($scope, element, attrs) {
var menuMain = $scope.$parent.menuMain;
var fullpath = $location.path().split('/');
var current = fullpath[2];
setTimeout(function() {
$(".nav li a").each(function() {
if ($(this).attr('href') == '#!/page/' + current) {
$(this).parent().addClass('active');
$(this).closest('li.root-li').addClass('active');
if ($(this).closest('li.parent').length > 0) {
$(this).closest('li.parent').addClass('active');
}
}
});
$(".nav li a").on('click', function() {
current = $(this).attr('href');
$("#pages-menu .navigation li").each(function() {
if ($(this).hasClass('active')) {
$(this).removeClass('active');
}
});
$(".nav li a").each(function() {
if ($(this).attr('href') == current) {
$(this).parent().addClass('active');
$(this).closest('li.root-li').addClass('active');
if ($(this).closest('li.parent').length > 0) {
$(this).closest('li.parent').addClass('active');
}
}
});
});
}, 500);
};
});
其給我像var htm =「Login」..我可以像訪問它htm.href ..但相反,如果我想訪問它像htm.attr('href'),怎麼樣 我可以做嗎?? – Amb
@amss我想你需要分享一些更多的細節你試圖迭代什麼樣的數據和什麼是所需的輸出 –
我編輯我的問題...我想用jquery替換angular.forEach – Amb