当前位置: 首页 > 面试题库 >

在React应用程序中无法将对象转换为原始值错误?

廉子民
2023-03-14
问题内容

我正在开发一个简单的react-
spring引导应用程序,但是由于GitHub问题,我使用IntelliJ重新创建了应用程序启动器文件,并使用先前应用程序的package.json文件的依赖项数据安装了节点模块。

如果我使用折叠的导航栏(汉堡栏->响应式导航栏,该导航栏在移动视图中折叠),然后单击“汉堡栏”按钮以查看导航链接,则会出现以下错误。但是所有这些事情在以前的应用程序中都进展顺利。

TypeError: Cannot convert object to primitive value
HTMLDivElement.<anonymous>
C:/Users/Hasindu/Documents/AF/Application Frameworks/online-fashion-store-master/src/main/js/src/collapse.js:346
  343 |   ...typeof config === 'object' && config ? config : {}
  344 | }
  345 | 
> 346 | if (!data && _config.toggle && /show|hide/.test(config)) {
      | ^  347 |   _config.toggle = false
  348 | }
  349 | 
View compiled
Function.each
C:/Users/Hasindu/Documents/AF/Application Frameworks/online-fashion-store-master/src/main/webapp/front-end/node_modules/jquery/dist/jquery.js:381
  378 | if ( isArrayLike( obj ) ) {
  379 |     length = obj.length;
  380 |     for ( ; i < length; i++ ) {
> 381 |         if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
      | ^  382 |            break;
  383 |         }
  384 |     }
View compiled
jQuery.fn.init.each
C:/Users/Hasindu/Documents/AF/Application Frameworks/online-fashion-store-master/src/main/webapp/front-end/node_modules/jquery/dist/jquery.js:203
  200 | 
  201 | // Execute a callback for every element in the matched set.
  202 | each: function( callback ) {
> 203 |     return jQuery.each( this, callback );
      | ^  204 | },
  205 | 
  206 | map: function( callback ) {
View compiled
jQuery.fn.init._jQueryInterface [as collapse]
C:/Users/Hasindu/Documents/AF/Application Frameworks/online-fashion-store-master/src/main/js/src/collapse.js:337
  334 | }
  335 | 
  336 | static _jQueryInterface(config) {
> 337 |   return this.each(function () {
      | ^  338 |     const $this   = $(this)
  339 |     let data      = $this.data(DATA_KEY)
  340 |     const _config = {
View compiled
HTMLDivElement.<anonymous>
C:/Users/Hasindu/Documents/AF/Application Frameworks/online-fashion-store-master/src/main/js/src/collapse.js:385
  382 |     const $target = $(this)
  383 |     const data    = $target.data(DATA_KEY)
  384 |     const config  = data ? 'toggle' : $trigger.data()
> 385 |     Collapse._jQueryInterface.call($target, config)
  386 |   })
  387 | })
  388 | 
View compiled
Function.each
C:/Users/Hasindu/Documents/AF/Application Frameworks/online-fashion-store-master/src/main/webapp/front-end/node_modules/jquery/dist/jquery.js:381
  378 | if ( isArrayLike( obj ) ) {
  379 |     length = obj.length;
  380 |     for ( ; i < length; i++ ) {
> 381 |         if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
      | ^  382 |            break;
  383 |         }
  384 |     }
View compiled
jQuery.fn.init.each
C:/Users/Hasindu/Documents/AF/Application Frameworks/online-fashion-store-master/src/main/webapp/front-end/node_modules/jquery/dist/jquery.js:203
  200 | 
  201 | // Execute a callback for every element in the matched set.
  202 | each: function( callback ) {
> 203 |     return jQuery.each( this, callback );
      | ^  204 | },
  205 | 
  206 | map: function( callback ) {
View compiled
HTMLButtonElement.<anonymous>
C:/Users/Hasindu/Documents/AF/Application Frameworks/online-fashion-store-master/src/main/js/src/collapse.js:381
  378 | const selector = Util.getSelectorFromElement(this)
  379 | const selectors = [].slice.call(document.querySelectorAll(selector))
  380 | 
> 381 | $(selectors).each(function () {
      | ^  382 |   const $target = $(this)
  383 |   const data    = $target.data(DATA_KEY)
  384 |   const config  = data ? 'toggle' : $trigger.data()
View compiled
HTMLDocument.dispatch
C:/Users/Hasindu/Documents/AF/Application Frameworks/online-fashion-store-master/src/main/webapp/front-end/node_modules/jquery/dist/jquery.js:5428
  5425 | event.handleObj = handleObj;
  5426 | event.data = handleObj.data;
  5427 | 
> 5428 | ret = ( ( jQuery.event.special[ handleObj.origType ] || {} ).handle ||
       | ^  5429 |  handleObj.handler ).apply( matched.elem, args );
  5430 | 
  5431 | if ( ret !== undefined ) {
View compiled
HTMLDocument.elemData.handle
C:/Users/Hasindu/Documents/AF/Application Frameworks/online-fashion-store-master/src/main/webapp/front-end/node_modules/jquery/dist/jquery.js:5232
  5229 | 
  5230 |        // Discard the second event of a jQuery.event.trigger() and
  5231 |        // when an event is called after a page has unloaded
> 5232 |        return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ?
       | ^  5233 |          jQuery.event.dispatch.apply( elem, arguments ) : undefined;
  5234 |    };
  5235 | }
View compiled
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.  Click the 'X' or hit ESC to dismiss this message.```

问题答案:

首先,删除jQuery:

npm remove jquery

然后重新安装它:

npm install jquery@~3.4.1


 类似资料:
  • 当对象相加 obj1 + obj2,相减 obj1 - obj2,或者使用 alert(obj) 打印时会发生什么? 在这种情况下,对象会被自动转换为原始值,然后执行操作。 在 类型转换 一章中,我们已经看到了数值,字符串和布尔转换的规则。但是我们没有讲对象的转换规则。现在我们已经掌握了方法(method)和 symbol 的相关知识,可以开始学习对象原始值转换了。 所有的对象在布尔上下文(con

  • 问题内容: 我将类的实例存储在中。 如何将Object 转换回类以访问class方法? 问题答案: 打字: 另外,如果是 class方法 ,则不需要 实例 来访问它,则可以直接调用它:

  • 我正在处理jBPM 7.22.0。最终的 我使用服务任务REST从这个api获取响应https://reqres.in/api/users/1 我想将此响应获取到一个对象中,因此我创建了这个类(或jBPM中调用的数据对象): 我在jBPM中创建了一个名为res的全局变量,该变量具有我要存储响应的数据对象的类型。因此,在我的REST服务任务的“任务”中,我有屏幕截图中的内容。 如您所见,我想将结果存

  • 服务器js 使用body parser中间件、把手和express 路线 客户 当记录我得到一个JSON字符串 {'{"满意":"文本1","改进":"文本2","评级":0.7}': '' } 我试着把这个字符串解析成一个对象。当我这样做时,我会收到这个错误消息 那么如何将字符串解析为对象呢? 通常我会执行。

  • 问题内容: 我有一个React应用程序,它基于某些配置生成HTML输出。像这样: 在react应用程序内部,我可以轻松地显示生成的DOM对象,但是我想将HTML代码保存到DB,以将其显示在其他页面上(而无需再次加载react / pars配置) 我找不到将JSX对象转换为纯HTML的方法… 问题答案: 使用renderToStaticMarkup方法-它生成HTML字符串,我们可以将其快速传输到线

  • 我正在我的反应应用程序中创建一个上一个和下一个按钮。我试图获取页面的当前索引(我有一个存储在对象中的页面列表) 这是密码 我得到的错误是“类型错误:无法将未定义或空转换为对象” 需要明确的是,imageName和images不是空的或未定义的(因为当I console.log它时,它有我需要的数据)。 提前谢谢!