javascript - 无法读取未定义的属性 'querySelectorAll'

标签 javascript ionic-framework

当我从其他 View 使用 ionic 时,我在控制台上收到此错误 Uncaught TypeError: Cannot read property 'querySelectorAll' of undefined ionic.bundle.js:2800,但我不知道这是什么意思,以及如何解决它

最佳答案

免责声明:我对 ionic 没有太多经验,这是基于我对一般 JavaScript 的经验。

您的错误可能来自于代码所依赖的特定元素,当您切换 View 时找不到该元素。我从 querySelectorAll 收集到这个作为元素的属性。它用于通过提供的 CSS Selector 获取子元素.它经常用作 document.querySelectorAll 以获取页面上与查询匹配的任何元素。

根据您提供给我们的信息,每次 View 更改时,您的代码(或内部库)似乎都在尝试对特定 View 中的元素使用 querySelectorAll,无论是否它是包含或不包含元素的 View 。这不可避免地导致特定元素为 undefined,因此没有 querySelectorAll 属性。这是一些模拟代码,它们会导致与您遇到的问题大致相同的问题。

# This would be run every time the view changes. 
let myElement = document.querySelectorAll('#element-in-different-view');
myElement === undefined; // true

myElement.querySelectorAll('#foo');
// undefined is not an Element, and as such doesn't have the property `querySelectorAll`

Important Note: As a community, we can provide you with more specific answers if you include the full traceback you get and a mvce.

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

相关文章:

javascript - 如何根据表单字段类型自动更新价格="number"

angularjs - 如何在手机上使用 MEAN 应用程序

angularjs - Ionic 3虚拟滚动只显示一小部分项目

forms - ion-input 类型的文本应该只接受字母 + ionic2

javascript - 在复杂的 json/数组中搜索位置以使用 javascript 进行更新(angularjs 或 pure)

javascript - SVG 下的 jQuery

angular - 在 ionic2 的日期时间选择器中订阅完成事件

angularjs - 在 Ionic 中设置 CORS

javascript - Sequelize : how to get flattened data, 基于嵌套关联加入表时?

javascript - 变异数组 Vuex