gpt4 book ai didi

javascript - 同位素 - 无法读取未定义的属性 'filteredItems'

转载 作者:数据小太阳 更新时间:2023-10-29 05:20:49 26 4
gpt4 key购买 nike

我正在尝试让我的同位素帖子页面与加载更多 按钮一起使用(如此处所示:https://codepen.io/bebjakub/pen/jWoYEO)。我有在 Codepen 上运行的代码,但我无法让它在网站上运行。

工作代码笔(我的(过滤和加载更多)- https://codepen.io/whitinggg/pen/qyvVwz

实时页面链接 - Here

我目前在控制台中看到关于我的 isotope.js 文件的错误:

Uncaught TypeError: Cannot read property 'filteredItems' of undefined
at loadMore (isotope.js?v=2.2.7:53)
at HTMLDocument.<anonymous> (isotope.js?v=2.2.7:48)
at i (jquery.js?ver=1.12.4:2)
at Object.fireWith [as resolveWith] (jquery.js?ver=1.12.4:2)
at Function.ready (jquery.js?ver=1.12.4:2)
at HTMLDocument.K (jquery.js?ver=1.12.4:2)

任何人都可以帮助解决此错误的含义吗?请帮助我解决它。

我的 Isotope.js 文件

jQuery(function ($) {


// with jQuery
var $container = $('.grid').isotope({
itemSelector: '.grid-item',
layoutMode: 'packery',
columnWidth: '.grid-sizer',
packery: {
gutter: '.gutter-sizer'
}
});

//Add the class selected to the item that is clicked, and remove from the others
var $optionSets = $('#filters'),
$optionLinks = $optionSets.find('a');

$optionLinks.click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('#filters');
$optionSets.find('.selected').removeClass('selected');
$this.addClass('selected');

//When an item is clicked, sort the items.
var selector = $(this).attr('data-filter');
$container.isotope({ filter: selector });

return false;
});

// layout Isotope after each image loads
$container.imagesLoaded().progress( function() {
$container.isotope('layout');
});


//****************************
// Isotope Load more button
//****************************
var initShow = 15; //number of items loaded on init & onclick load more button
var counter = initShow; //counter for load more button
var iso = $container.data('grid'); // get Isotope instance

loadMore(initShow); //execute function onload

function loadMore(toShow) {
$container.find(".hidden").removeClass("hidden");

var hiddenElems = iso.filteredItems.slice(toShow, iso.filteredItems.length).map(function(item) {
return item.element;
});
$(hiddenElems).addClass('hidden');
$container.isotope('layout');

//when no more to load, hide show more button
if (hiddenElems.length == 0) {
jQuery("#load-more").hide();
} else {
jQuery("#load-more").show();
};

}

//append load more button
$container.after('<button id="load-more"> Load More</button>');

//when load more button clicked
$("#load-more").click(function() {
if ($('#filters').data('clicked')) {
//when filter button clicked, set initial value for counter
counter = initShow;
$('#filters').data('clicked', false);
} else {
counter = counter;
};

counter = counter + initShow;

loadMore(counter);
});

//when filter button clicked
$("#filters").click(function() {
$(this).data('clicked', true);

loadMore(initShow);
})


});

最佳答案

为什么它在 codepen 上工作而在我的网站上没有工作的背后的问题原来是一个简单的问题。不记得为什么我现在这样做了,但我已经从 Codepen 到站点稍微更改了一行代码,这似乎导致了这个问题。那一行是:

var iso = $container.data('grid'); // get Isotope instance

应该是:

var iso = $container.data('isotope'); // get Isotope instance

关于javascript - 同位素 - 无法读取未定义的属性 'filteredItems',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51981689/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com