2013-05-13 1 views
0
if (Meteor.isClient) { 

Template.articles.rendered = function() { 

    var container = $('.articles'); 
    var antiIso = $(container.find(".article:not(.isotope-item)")); 

    if(container.children().length > 0) { 

     if (!container.hasClass("isotope")) { 
      console.log(container); 
      console.log(container.hasClass("isotope")); 

      container.isotope({ 
       // options 
       itemSelector : '.article', 
       layoutMode : 'fitRows' 
      }); 

     } else if (container.hasClass("isotope") && antiIso.length > 0) { 

      console.log("Updating Isos"); 

      container.isotope('addItems', antiIso, function() { 
       container.isotope(); 
      }); 

     } 

    } 

} 

콘솔 출력 :동위 원소, 유성, hasClass가 false를 반환합니까?

<div class="articles isotope" style="position: relative; overflow: hidden; height: 281px; ">…</div> 
false 

내가 여기 노골적으로 뭔가를 분명 실종? 내 이해 컨테이너에 반드시 동위 원소 클래스가 있어야합니까?

답변

1

나는 console.log가 완전히 상상 한 방식으로 작동하지 않는다는 것을 깨달았지만, 세 번이나 동위 원소 클래스가 나타납니다. console.log는 매번 객체의 최종 결과를 보여주었습니다.

따라서 코드가 올바르게 작동하고 있었지만 제대로 작동하지 않았습니다. 아래 코드를 수정하여 문제를 해결했습니다.

if (Meteor.isClient) { 

Template.articles.rendered = function() { 

    var container = $('.articles'); 
    var antiIso = $(container.find(".article:not(.isotope-item)")); 

    if(container.children().length > 0) { 

     if (!container.hasClass("isotope") && antiIso) { 

      container.isotope({ 
       // options 
       itemSelector : '.article', 
       layoutMode : 'fitRows' 
      }); 

     } else if (container.hasClass("isotope") && antiIso.length > 0) { 

      console.log("Updating Isos"); 

      container.isotope('addItems', antiIso, function() { 
       container.isotope(); 
      }); 

     } 

    } 

}