Home > Web Front-end > JS Tutorial > Solutions to JavaScript program errors

Solutions to JavaScript program errors

巴扎黑
Release: 2017-07-23 15:23:55
Original
2268 people have browsed it
When programming today, the JavaScript program reported this error: Cannot use 'in' operator to search for..., the specific error message is as follows:
Frankly speaking, errors like this are the most difficult to debug. Because it does not point to the specific code you wrote, but generally points to the lib.js file (this file is usually a third-party packaging and compression library), you can hardly locate the actual programming problem based on the error type and error direction. Wrong location.
what to do?
At this time, the only way to show off is the spirit of "fight to the death"!
Frustrating steps:
  1. It should not be difficult to locate the wrong file based on the fault page and error message;

  2. In the error page, click Debug one by one to see at which step the error started to appear! Very critical! For example, if an error occurs at the beginning of loading, then locate the initialization part of the js file; if an error occurs when clicking a button, then locate the corresponding event code of the button; and so on.

  3. Within the scope of the positioned code, use the "compromise method" and comment it out bit by bit. Refresh the page to see if the error still occurs. If there is an error, it means that there is no problem with the commented out part of the code. , release the comments, and continue with other suspicious code parts; if there are no errors, congratulations, your positioning will be more refined! The general idea is like this, keep going in circles, I believe, there will always be the joy of "pushing away the clouds and seeing the bright blue sky"!

1 console.log('rendernerererer: ', schoolData)2 3 const schoolNode = (4     <Select style={{width: &#39;100%&#39;}} placeholder="请选择所属学校">5         { schoolData.length && schoolData.map((item, idx) => (6             <Option key={idx} value={`${item.id}`}>{item.name}</Option>7         )) }8     </Select>9 );
Copy after login

You can see that rendernerererer prints correctly The problem is after this line of code:

 1 const schoolData = this.state.schoolList; 2 console.log('rendernerererer: ', schoolData) 3   4 const schoolNode = ( 5     <Select style={{width: &#39;100%&#39;}} placeholder="请选择所属学校"> 6         { schoolData.length ? schoolData.map((item, idx) => ( 7             <Option key={idx} value={`${item.id}`}>{item.name}</Option> 8         )) : <Option value=&#39;&#39;>请选择...</Option> } 9     </Select>10 );
Copy after login

##
 1 const schoolData = this.state.schoolList; 2 console.log('rendernerererer: ', schoolData) 3   4 const schoolNode = ( 5     <Select style={{width: &#39;100%&#39;}} placeholder="请选择所属学校"> 6         { schoolData.length ? schoolData.map((item, idx) => ( 7             <Option key={idx} value={`${item.id}`}>{item.name}</Option> 8         )) : null } 9     </Select>10 );
Copy after login

The above is the detailed content of Solutions to JavaScript program errors. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template