Uncaught TypeError: querySelector is not a function

Uncaught TypeError: querySelector is not a function

遇到一个非常奇怪的 JS 错误。

我正在使用 isotope.js 通过一些过滤器按钮和搜索字段来过滤项目,例如 this example

我的用例略有不同,因为我要搜索父元素中特定子元素的内容,而不是整个元素。我对示例代码进行了一些编辑以满足我的需要并将其转换为原始 JS,因此我的初始化版本如下所示:

var qsRegex;
var buttonFilter;

var iso = new Isotope('.gridListing', {
    itemSelector: '.gridItem',
    percentPosition: true,
    layoutMode: 'fitRows',
    stagger: 30,
    filter: function(itemElem) {
        var name = itemElem.querySelector('.name').textContent;
        const searchResult = qsRegex ? text.match(qsRegex) : true;
        const buttonResult = buttonFilter ? itemElem.classList.contains(buttonFilter) : true;
        return searchResult && buttonResult;
    },
    masonry: {
    columnWidth: '.grid-sizer'
  }
});

此代码在我使用 WebPack 运行ning 的本地环境中工作得非常好。当我编译代码并复制到我的实时站点 运行 安装 WordPress 时,我收到以下错误消息。

"Uncaught TypeError: itemElem.querySelector is not a function"

我不确定什么会导致代码在本地 运行 正常但在实时服务器上失败。如果有人能指出我正确的方向,那将非常有帮助。

) 试试这个过滤块

filter: function(index, item) {
    var name = item.querySelector('.name').textContent;
    const searchResult = qsRegex ? text.match(qsRegex) : true;
    const buttonResult = buttonFilter ? item.classList.contains(buttonFilter) : true;
    return searchResult && buttonResult;
},