Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 找不到角JS对象_Javascript_Jquery_Angularjs - Fatal编程技术网

Javascript 找不到角JS对象

Javascript 找不到角JS对象,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我有一个角度的对象,它正在我使用的库中使用。当我编写一个新函数时,我不能传递相同的对象。我不知道为什么 该对象称为person。它直接绑定在HTML中。该对象仅从下面的cardsCollection数组返回2项 我尝试编写的函数叫做clickLike。我真的只是想让同样的事情发生,不管是有人点击还是刷卡正确。您可以在此处看到开发人员站点: 以下是整个controller.js文件: angular.module('black-label', ['ngTouch', 'ngSwippy']) .

我有一个角度的对象,它正在我使用的库中使用。当我编写一个新函数时,我不能传递相同的对象。我不知道为什么

该对象称为
person
。它直接绑定在HTML中。该对象仅从下面的cardsCollection数组返回2项

我尝试编写的函数叫做clickLike。我真的只是想让同样的事情发生,不管是有人点击还是刷卡正确。您可以在此处看到开发人员站点:

以下是整个controller.js文件:

angular.module('black-label', ['ngTouch', 'ngSwippy'])
.controller('MainController', function($scope, $timeout, $window) {
    $scope.cardsCollection = [
      {
          thumbnail: 'images/deck/thor_01.jpg',
          collection: 'thoroughbred',
      }, {
          thumbnail: 'images/deck/thor_02.jpg',
          collection: 'thoroughbred',
      }, {
          thumbnail: 'images/deck/thor_03.jpg',
          collection: 'thoroughbred',
      }, {
          thumbnail: 'images/deck/thor_04.jpg',
          collection: 'thoroughbred',
      }, {
          thumbnail: 'images/deck/thor_05.jpg',
          collection: 'thoroughbred',
      }, {
          thumbnail: 'images/deck/thor_06.jpg',
          collection: 'thoroughbred',
      }, {
          thumbnail: 'images/deck/rhap_01.jpg',
          collection: 'rhapsody',
      }, {
          thumbnail: 'images/deck/rhap_02.jpg',
          collection: 'rhapsody',
      }, {
          thumbnail: 'images/deck/rhap_03.jpg',
          collection: 'rhapsody',
      }, {
          thumbnail: 'images/deck/rhap_04.jpg',
          collection: 'rhapsody',
      }, {
          thumbnail: 'images/deck/rhap_05.jpg',
          collection: 'rhapsody',
      }, {
          thumbnail: 'images/deck/rhap_06.jpg',
          collection: 'rhapsody',
      }, {
          thumbnail: 'images/deck/cha_01.jpg',
          collection: 'chalet',
      }, {
          thumbnail: 'images/deck/cha_02.jpg',
          collection: 'chalet',
      }, {
          thumbnail: 'images/deck/cha_03.jpg',
          collection: 'chalet',
      }, {
          thumbnail: 'images/deck/cha_04.jpg',
          collection: 'chalet',
      }, {
          thumbnail: 'images/deck/cha_05.jpg',
          collection: 'chalet',
      }, {
          thumbnail: 'images/deck/cha_06.jpg',
          collection: 'chalet',
      }, {
          thumbnail: 'images/deck/mod_01.jpg',
          collection: 'modern',
      }, {
          thumbnail: 'images/deck/mod_02.jpg',
          collection: 'modern',
      }, {
          thumbnail: 'images/deck/mod_03.jpg',
          collection: 'modern',
      }, {
          thumbnail: 'images/deck/mod_04.jpg',
          collection: 'modern',
      }, {
          thumbnail: 'images/deck/mod_05.jpg',
          collection: 'modern',
      }, {
          thumbnail: 'images/deck/mod_06.jpg',
          collection: 'modern',
      }, {
          thumbnail: 'images/deck/ind_01.jpg',
          collection: 'indulgence',
      }, {
          thumbnail: 'images/deck/ind_02.jpg',
          collection: 'indulgence',
      }, {
          thumbnail: 'images/deck/ind_03.jpg',
          collection: 'indulgence',
      }, {
          thumbnail: 'images/deck/ind_04.jpg',
          collection: 'indulgence',
      }, {
          thumbnail: 'images/deck/ind_05.jpg',
          collection: 'indulgence',
      }, {
          thumbnail: 'images/deck/ind_06.jpg',
          collection: 'indulgence',
      }, {
          thumbnail: 'images/deck/cnt_01.jpg',
          collection: 'center-stage',
      }, {
          thumbnail: 'images/deck/cnt_02.jpg',
          collection: 'center-stage',
      }, {
          thumbnail: 'images/deck/cnt_03.jpg',
          collection: 'center-stage',
      }, {
          thumbnail: 'images/deck/cnt_04.jpg',
          collection: 'center-stage',
      }, {
          thumbnail: 'images/deck/cnt_05.jpg',
          collection: 'center-stage',
      }, {
          thumbnail: 'images/deck/cnt_06.jpg',
          collection: 'center-stage',
      }, {
          thumbnail: 'images/deck/vin_01.jpg',
          collection: 'vineyard',
      }, {
          thumbnail: 'images/deck/vin_02.jpg',
          collection: 'vineyard',
      }, {
          thumbnail: 'images/deck/vin_03.jpg',
          collection: 'vineyard',
      }, {
          thumbnail: 'images/deck/vin_04.jpg',
          collection: 'vineyard',
      }, {
          thumbnail: 'images/deck/vin_05.jpg',
          collection: 'vineyard',
      }, {
          thumbnail: 'images/deck/vin_06.jpg',
          collection: 'vineyard',
      }, 
    ];

    // Do the shuffle
    var shuffleArray = function(array) {
        var m = array.length,
            t, i;
        // While there remain elements to shuffle
        while (m) {
            // Pick a remaining element
            i = Math.floor(Math.random() * m--);
            // And swap it with the current element.
            t = array[m];
            array[m] = array[i];
            array[i] = t;
        }
        return array;
    };
    $scope.deck = shuffleArray($scope.cardsCollection);

    $scope.myCustomFunction = function() {
      $timeout(function() {
        $scope.clickedTimes = $scope.clickedTimes + 1;
        $scope.actions.unshift({ name: 'Click on item' });
      });
    };

    $scope.count = 0;
    $scope.showinfo = false;
    $scope.clickedTimes = 0;
    $scope.actions = [];
    $scope.picks = [];
    var counterRight = 0;
    var counterLeft = 0;

    $scope.swipeend = function() {
        $scope.actions.unshift({ name: 'Collection Empty' });
        $window.location.href = 'theme-default.html';
    }; //endswipeend

    $scope.swipeLeft = function(person) {
        //Essentially do nothing
        $scope.actions.unshift({ name: 'Left swipe' });
        $('.circle.x').addClass('dislike');
        $('.circle.x').removeClass('dislike');
        $(this).each(function() {
            return counterLeft++;
        });
    }; //end swipeLeft

    $scope.swipeRight = function(person) {
      $scope.actions.unshift({ name: 'Right swipe' });

      // Count the number of right swipes
      $(this).each(function() {
          return counterRight++;
      });
      // Checking the circles
      $('.circle').each(function() {
          if (!$(this).hasClass('checked')) {
              $(this).addClass('checked');
              return false;
          }
      });

      $('.icon-like').addClass('liked');
      $('.icon-like').removeClass('liked');

      $scope.picks.push(person.collection);
      // console.log('Picks: ' + $scope.picks);
      // console.log("Counter: " + counterRight);
      if (counterRight === 4) {
          // Calculate and store the frequency of each swipe
          var frequency = $scope.picks.reduce(function(frequency, swipe) {
              var sofar = frequency[swipe];
              if (!sofar) {
                  frequency[swipe] = 1;
              } else {
                  frequency[swipe] = frequency[swipe] + 1;
              }
              return frequency;
          }, {});

          var max = Math.max.apply(null, Object.values(frequency)); // most frequent
          // find key for the most frequent value
          var winner = Object.keys(frequency).find(element => frequency[element] == max);
          $window.location.href = 'theme-' + winner + '.html';

      } //end 4 swipes
    }; //end swipeRight

    $scope.clickLike = function() {
      $scope.swipeRight();
    }; //clickLike
});
甲板的HTML文件

<div class="ng-swippy noselect">
<div person="person" swipe-directive="swipe-directive" ng-repeat="person in peopleToShow" class="content-wrapper swipable-card">
  <div class="card">
      <div style="background: url({{person.thumbnail}}) no-repeat 50% 15%" class="photo-item"></div>
      <div class="know-label">{{labelOk ? labelOk : "YES"}}</div>
      <div class="dontknow-label">{{labelNegative ? labelNegative : "NO"}}</div>
  </div>
  <div class="progress-stats" ng-if="data">
      <div class="card-shown">
          <div class="card-shown-text">{{person.collection}}</div>
          <div class="card-shown-number">{{person.subtitle}}</div>
      </div>
      <div class="card-number">{{collection.length - (collection.indexOf(person))}}/{{collection.length}}&nbsp;
      </div>
  </div>
  <div class="container like-dislike" >
    <div class="circle x" ng-click="$parent.$parent.clickDisike()"></div>
    <div class="icon-like" ng-click="$parent.$parent.clickLike()"></div>
    <div class="clearfix"></div>
  </div>
</div><!-- end person-->
<div class="clearfix"></div>

{{拉贝洛克?拉贝洛克:“是的”}
{{labelNegative?labelNegative:“否”}
{{person.collection}
{{person.subtitle}
{{collection.length-(collection.indexOf(person))}/{{collection.length}

如果我遗漏了什么,请告诉我


提前谢谢大家

我看不出你是如何让
人们看到的

ng-repeat="person in peopleToShow"
您可能希望将其替换为:

ng-repeat="person in cardsCollection"

因为
$scope.cardsCollection
似乎是存储缩略图的地方。

我看不出你是如何让
人看到

ng-repeat="person in peopleToShow"
您可能希望将其替换为:

ng-repeat="person in cardsCollection"

因为
$scope.cardsCollection
似乎是存储缩略图的地方。

我就是这么想的。但是,该应用程序与
ng repeat=“peopleToShow中的人”配合使用效果很好。这是我正在使用的图书馆的链接。似乎
person
对象仅对swipeRight和swipeLeft方法可用。如果在开发工具中打开
ng swippy.js
,您将在第148行看到person对象。这就是我的想法。但是,该应用程序与
ng repeat=“peopleToShow中的人”配合使用效果很好。这是我正在使用的图书馆的链接。似乎
person
对象仅对swipeRight和swipeLeft方法可用。如果在开发工具中打开
ng swippy.js
,您将在第148行看到person对象。