Почему jQuery не выполняет условие?

196
11 февраля 2019, 20:20

может кто то объяснить, почему не работает $('..').css()

Поставил id только для проверки, так же не работает на все span и так далее.

    angular.module('profilePage').component('profilePage', {
    templateUrl: 'app/components/profile-page/profile-page.template.html',
    controller: ['$http', '$scope', function ProfilePageController($http, $scope){
        var account_id = 131389547;
        var api_key = '706700BD62A6A2A65A14C30E3D1A7260';

        $http({
            method : 'GET',
            url : 'https://api.opendota.com/api/players/' + account_id + '/',
            params: {
                'api_key' : api_key
            }
    }).then(function success(response){
        $scope.data = response.data;
        $scope.profile = response.data.profile;
        console.log(response.data);
        $scope.rank = response.data.rank_tier;
        $http({
            method: 'GET',
            url: '../assets/medal.json'
        }).then(function(ranks){
            $scope.medal = ranks.data;
            console.log($scope.rank);
            console.log($scope.medal);
            console.log($scope.medal.ranks.length);
            for(let rk = 0; rk < ranks.data.ranks.length; rk++){
                if($scope.rank == $scope.medal.ranks[rk].id){
                    $scope.rank = $scope.medal.ranks[rk].image;
                    console.log($scope.rank);
                }
            };
        }, function(ranks){
        })
        $http({
            method : 'GET',
            url : 'https://api.opendota.com/api/players/' + account_id + '/peers',
            params: {
                'api_key' : api_key
            }
        }).then(function(profilepeers){
            $scope.profilepeer = profilepeers.data;
            for(let peer = 0; peer < $scope.profilepeer.length; peer++){
                $scope.profilepeer[peer].win_rate_peer = ($scope.profilepeer[peer].with_win / $scope.profilepeer[peer].with_games)*100;
            };
            console.log($scope.profilepeer);
        }, function(profilepeer){
        });

    }, function failed(response) {
        alert('Bad request!');
    })


    $http({
        method : 'GET',
        url : 'https://api.opendota.com/api/players/' + account_id + '/wl',
        params: {
            'api_key' : api_key
        }
    }).then(function success(winlose){
        $scope.stats = winlose.data;
        console.log(winlose);
        $scope.winrate = ($scope.stats.win / ($scope.stats.win + $scope.stats.lose))*100;

    }, function failed(winlose) {
        alert('Bad request!');
    })

    $http({
        method: 'GET',
        url: 'https://api.opendota.com/api/players/' + account_id +'/recentmatches',
        params: {
            'api_key': api_key
        }
    }).then(function success(response){
        $scope.matches = response.data;
        console.log($scope.matches);

        for(let wl = 0; wl < $scope.matches.length; wl++){
            if($scope.matches[wl].radiant_win == true && $scope.matches[wl].player_slot <= 127){
                $scope.matches[wl].radiant_win = 'win';
            } else if ($scope.matches[wl].radiant_win == false && $scope.matches[wl].player_slot <= 127) {
                $scope.matches[wl].radiant_win = 'lose';
            } else if ($scope.matches[wl].radiant_win == true && $scope.matches[wl].player_slot >= 128) {
                $scope.matches[wl].radiant_win = 'lose';
            } else if ($scope.matches[wl].radiant_win == false && $scope.matches[wl].player_slot >= 128) {
                $scope.matches[wl].radiant_win = 'win';
            }
        };

        for(let q = 0; q < response.data.length; q++){
            if($scope.matches[q].skill == '0'){
                $scope.matches[q].skill = 'Unknow';
            } else if($scope.matches[q].skill == '1'){
                $scope.matches[q].skill = 'Normal Skill';
            } else if($scope.matches[q].skill == '2'){
                $scope.matches[q].skill = 'High Skill';
            } else if($scope.matches[q].skill == '3'){
                $scope.matches[q].skill = 'Very High Skill';
            }
        };
        for(let cls = 0; cls < $scope.matches.length; cls++){
            console.log($scope.matches[cls].radiant_win);
            if($scope.matches[cls].radiant_win == 'win'){
                $("#winlose").css("color", "green");
            } else if($scope.matches[cls].radiant_win == 'lose'){
                $("#winlose").css("color", "red");
            }
        };
        for (let i = 0; i < response.data.length; i++){
            $scope.matches[i].duration = Math.ceil($scope.matches[i].duration / 60) + ':' + Math.ceil($scope.matches[i].duration % 60);
            if ($scope.matches[i].game_mode == '0') {
                $scope.matches[i].game_mode = 'No Game Mode';
            } else if ($scope.matches[i].game_mode == '1') {
                $scope.matches[i].game_mode = 'All Pick';
            } else if ($scope.matches[i].game_mode == '2') {
                $scope.matches[i].game_mode = "Captain's Mode";
            } else if ($scope.matches[i].game_mode == '3') {
                $scope.matches[i].game_mode = 'Random Draft';
            } else if ($scope.matches[i].game_mode == '4') {
                $scope.matches[i].game_mode = 'Single Draft';
            } else if ($scope.matches[i].game_mode == '5') {
                $scope.matches[i].game_mode = 'All Random';
            } else if ($scope.matches[i].game_mode == '6') {
                $scope.matches[i].game_mode = 'Intro';
            } else if ($scope.matches[i].game_mode == '7') {
                $scope.matches[i].game_mode = "Diretide";
            } else if ($scope.matches[i].game_mode == '8') {
                $scope.matches[i].game_mode = "Reverse Captain's Mode";
            } else if ($scope.matches[i].game_mode == '9') {
                $scope.matches[i].game_mode = 'Greeviling';
            } else if ($scope.matches[i].game_mode == '10') {
                $scope.matches[i].game_mode = 'Tutorial';
            } else if ($scope.matches[i].game_mode == '11') {
                $scope.matches[i].game_mode = 'Mid Only';
            } else if ($scope.matches[i].game_mode == '12') {
                $scope.matches[i].game_mode = 'Least Played';
            } else if ($scope.matches[i].game_mode == '13') {
                $scope.matches[i].game_mode = 'New Player Pool';
            } else if ($scope.matches[i].game_mode == '14') {
                $scope.matches[i].game_mode = 'Compendium Matchmaking';
            } else if ($scope.matches[i].game_mode == '15') {
                $scope.matches[i].game_mode = "Custom";
            } else if ($scope.matches[i].game_mode == '16') {
                $scope.matches[i].game_mode = "Captain's Draft";
            } else if ($scope.matches[i].game_mode == '17') {
                $scope.matches[i].game_mode = 'Balanced Draft';
            } else if ($scope.matches[i].game_mode == '18') {
                $scope.matches[i].game_mode = 'Ability Draft';
            } else if ($scope.matches[i].game_mode == '19') {
                $scope.matches[i].game_mode = 'Custom Game';
            } else if ($scope.matches[i].game_mode == '20') {
                $scope.matches[i].game_mode = 'All Random Deathmatch';
            } else if ($scope.matches[i].game_mode == '21') {
                $scope.matches[i].game_mode = 'Solo Mid 1v1';
            } else if ($scope.matches[i].game_mode == '22') {
                $scope.matches[i].game_mode = 'Ranked All Pick';
            }
            else if ($scope.matches[i].game_mode == '23') {
                $scope.matches[i].game_mode = 'Turbo';
            } 
        };


        $http({
            method: 'GET',
            url: '../assets/heroes.json'
        }).then(function success(heroes){
            // console.log(JSON.stringify(heroes.data));
            $scope.hero = heroes.data;
            for(let k = 0; k < response.data.length; k++){
                for (n = 0; n < heroes.data.length; n++){
                    if ($scope.matches[k].hero_id == $scope.hero[n].id) {
                        $scope.matches[k].hero_id = $scope.hero[n].localized_name;
                        $scope.matches[k].url = $scope.hero[n].url;
                        // console.log($scope.matches);
                    }
                }
            }

            $http({
                method: 'GET',
                url: 'https://api.opendota.com/api/players/' + account_id + '/heroes',
                params: {
                    'api_key': api_key
                }
            }).then(function(bestHeroes){
                $scope.bestHero = bestHeroes.data;
                console.log($scope.bestHero)
                for(let f = 0; f < bestHeroes.data.length; f++){
                    for(let n = 0; n < heroes.data.length; n++){
                        if($scope.bestHero[f].hero_id == $scope.hero[n].id){
                            $scope.bestHero[f].hero_id = $scope.hero[n].localized_name;
                            $scope.bestHero[f].url = $scope.hero[n].url;
                            $scope.bestHero[f].win_rate = ($scope.bestHero[f].win / $scope.bestHero[f].games) * 100 + '%';
                        }
                    }
                };
                }, function failed(bestHeroes){
            })
        }, function failed(heroes){
        })
    }, function failed(response){
    });
        (function($){
          $(function() {
            $('.menu__icon').on('click', function() {
              $(this).closest('.menu').toggleClass('menu_state_open');
            });
          });
        })(jQuery);

        $(".function-content a").click(function(e) {
          e.preventDefault();
          $(".function-content a").removeClass('chosen');
          $(this).addClass('chosen');
        });
}]
}).filter('firstWord', firstWord).filter('other', other);
    firstWord.$inject = ['$filter'];
    other.$inject = ['$filter'];

    function firstWord($filter) {
        return function(data) {
            if(!data) return data;
            data = data.split(' ');
            return data[0];
        };
    };
    function other($filter) {
        return function(data) {
            if(!data) return data;
            data = data.split(' ').slice(1,3).join(' ');
            return data;
        };
    };
Answer 1

Два варианта.

Первый.

Код на картинке находится внутри обработчика, выполняемого в процессе сабмита формы или GET-перехода на эту же самую страницу, и Вы не успеваете увидеть изменений стилей.

Второй.

В сравниваемых строках смешаны латинские буквы и кириллица. Визуально одинаковые строки одинаковыми не являются.

Хорошо, предположим DOM-элементов в выборке $(".span-winlose") столько же сколько объектов в массиве $scope.matches:

    for(let cls = 0; cls < $scope.matches.length; cls++){
        console.log($scope.matches[cls].radiant_win);
        if($scope.matches[cls].radiant_win == 'win'){
            $(".span-winlose").eq(cls).css("color", "green");
        } else if($scope.matches[cls].radiant_win == 'lose'){
            $(".span-winlose").eq(cls).css("color", "red");
        }
    };
READ ALSO
Как сделать задержку анимации на SASS?

Как сделать задержку анимации на SASS?

1) Надо сделать ее непрерывной 2) В конце анимации нужно сделать чтобы была задержка например 3s

168
как запустить OpenVPN в SSIS?

как запустить OpenVPN в SSIS?

Подскажите, пожалуйста, как запустить OpenVPN в пакете SSIS? У меня есть удаленная БД MySQL к которой я подключаюсь MS SQL Server через VPN-соединение которая...

159
page-break-inside для SVG g тэгов?

page-break-inside для SVG g тэгов?

Можно ли предотвратить разрыв страницы при печати, чтобы <g> тэги svg не разрывались, а переносились на следующую страницу?

185
Треугольники из radio input [закрыт]

Треугольники из radio input [закрыт]

Есть варианты как сверстать это внутри ячейки таблицы?

217