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();
            });

        }

    }

}

控制台输出:

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

我在这里错过了什么明显的东西吗?据我了解,容器肯定应该有同位素类?

4

1 回答 1

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();
            });

        }

    }

}
于 2013-05-13T01:10:45.407 回答