2014-07-23 7 views
2

나는 undefined is not a function 오류의 의미를 알고 있지만 왜 여기에 나타나는지 알 수 없습니다.벽돌 : 정의되지 않은 함수가 아닙니다.

방금 ​​마지막 Masonry 버전을 다운로드하고 문서를 따라 가려고했습니다. (http://desandro.github.io/masonry/docs/methods.html)

레이아웃이 정상적으로 작동하지만 전혀 masonry() 기능을 사용할 수없는 것 같습니다. 내 masonry() 호출에 항상 undefined is not a function 오류가 발생합니다.

레이아웃이 작동하고 있기 때문에 벽돌 스크립트가 정상적으로 작동한다고 가정하고 있습니다. 이 없으면 masonry(...)을 사용할 수없는 이유는 무엇입니까?

은 (내가 V3를 벽돌하는 벽돌 v2에서 변화를 검색하지만,이 기능과 관련된 아무것도 찾을 수 없습니다)

부분 HTML 코드 : 따라서 당신은 jQuery를하기 전에 벽돌을로드

<a class="navbar-brand" id ="test-masonry" href="#">...</a> 

<div id="masonry-container" class="js-masonry" data-masonry-options='{ "columnWidth": 330, "itemSelector": ".item" }'> 
    <div class="item"> 
     <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#createNewBlock">Create a new block</button> 
    </div> 
</div> 

<!-- Freshly downloaded from the official Masonry website --> 
<script src="js/masonry.pkgd.min.js"></script> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<script src="js/bootstrap.min.js"></script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script> 
<script src="js/app.js"></script> 
<script src="js/controllers/appCtrl.js"></script> 

<!-- Copied from the example in the docs --> 
<script> 
$(function(){ 
    var $container = $('#masonry-container'); 
    $('#test-masonry').click(function(){ 
     var $boxes = $('<div>Test !</div>'); 
     $container.prepend($boxes).masonry('reload'); 
    }); 
}); 
</script> 

답변

9

, 왜 undefined이 나옵니까? 벽돌을 포함 할 때 jQuery가로드되었는지 확인합니다. 이 경우, jQuery 객체에 Masonry 속성을 설정합니다 : $.fn.masonry. 따라서 jQuery보다 먼저 Masonry를로드하면 jQObject.masonry()을 사용할 수 없습니다.

벽돌이 작동하지 않아서 jQuery가 작동하지 않아 레이아웃이 제대로 작동합니다.

+0

고마워, 그게 문제였습니다. 하지만 "jQuery를 두 번로드하는"방법은 Angular와 jQLite와 관련이 있을지 모르겠습니다. – Sugar

+0

아마도 CMS를 사용하고 있습니까? –

+0

Nop. Masonry, JQuery, AngularJS 및 Bootstrap. 그게 전부 야. 신경 쓰지 마, 지금 일하고있어. – Sugar

관련 문제