2011-11-21 5 views
2

Namaste!jQuery "array"가 반환됩니다. 정의되지 않음

내 간단한 문제는 $ sortedData가 실행시 다음 코드에서 정의되지 않은된다 있다는 것입니다 :

(function($) { 
       $.fn.shuffle = function(){ 
        var i = this.length, j, temp; 
        if (i == 0) { return; } 
        while (--i) { 
         j = Math.floor(Math.random() * (i + 1)); 
         temp = this[i]; 
         this[i] = this[j]; 
         this[j] = temp; 
        } 
       }; 
      })(jQuery); 

// DOMContentLoaded 
      $(function() { 
       // get the first collection 
       var $cards = $('#cards'); 
       // clone cards to get a second collection 
       var $data = $cards.clone(); 
       // call Quicksand when button clicked 
       $('#shuffle').click(function(e) { 
       // get all the list items 
       var $filteredData = $data.find('li'); 
       // random sort (shuffling) 
       var $sortedData = $filteredData.shuffle(); 
       // finally, call quicksand 
       $cards.quicksand($sortedData, { 
        duration: 600, 
        easing: 'easeInOutQuad' 
       }); 
       }); 

      }); 

이 호출되는 방법 : 나는 클릭하면 위의 코드를 실행하는 버튼이 있습니다.

shuffle 함수의 값을 확인한 후 shuffle 함수를 호출하기 전에 shuffle 함수가 반환하면 $ sortedData가 정의되지 않았습니다.

오류는 아마도 멍청한 것이지만, 나는 그것을 볼 수 없습니다.

입력 해 주셔서 감사합니다.

+1

'shuffle' 메쏘드에'return' 문이 없습니다. – Esailija

답변

3

"셔플"기능은 아무 것도 반환하지 않지만 마치 마치 그 것처럼 취급합니다. 제자리에서 뒤섞이는 것처럼 보입니다.

+0

예, 'twas noobish ... –

관련 문제