简体   繁体   English

ReactJS不使用&&显示数据

[英]ReactJS not showing data using &&

I am writing a code that will read data from JSON file towards reactJS file. 我正在编写一个代码,该代码将从JSON文件中的数据读取到reactJS文件。 This JSON file contain multiple pages which starts at "context" then "pageNumber". 此JSON文件包含多个页面,这些页面以“上下文”开始,然后是“ pageNumber”。 When i do not include 当我不包括

&& (details.context.pageNumber)) &&(details.context.pageNumber))

The output will then show only the data content from the latest page for example if there is 20 pages of file in the JSON file it will show the data from the 20th page. 然后,输出将仅显示最新页面中的数据内容,例如,如果JSON文件中有20页文件,它将显示第20页中的数据。

But when i put in the source code above, It supposed to show all the pages content but it does not show content and it shows this error instead. 但是,当我输入上面的源代码时,它应该显示所有页面的内容,但不显示内容,而是显示此错误。

Here are the source code : 这是源代码:

componentDidMount(){
     let jsonData01 = data01
     jsonData01.responses.map((details,index) =>{
     return jsonData01 = ((details.fullTextAnnotation.text) && (details.context.pageNumber));
     })
console.log(`File Content JSON:\n`+ jsonData01);
}

Here are the error Output : 这是错误输出:

在此处输入图片说明

Any ideas or solutions guys ? 有什么想法或解决方案的家伙吗?

My JSON file can be seen here : https://drive.google.com/file/d/15tbyQLjylsefeXxEAmU4HmNn9OHyZxLA/view?usp=sharing 在这里可以看到我的JSON文件: https : //drive.google.com/file/d/15tbyQLjylsefeXxEAmU4HmNn9OHyZxLA/view?usp=sharing

The (details.fullTextAnnotation.text) from your JSON might be not available or null. JSON中的(details.fullTextAnnotation.text)可能不可用或为null。 That's why you are getting only page number. 这就是为什么只获得页码的原因。 Check your JSON once. 一次检查您的JSON。

Further if you are using jsonData01 inside of <Table> tag, this is the cause of warning. 此外,如果在<Table>标记内使用jsonData01 ,则这是警告的原因。 If you want to show data in table then format your data to appropriate row tag ie <tr></tr> tag. 如果要在表中显示数据,则将数据格式化为适当的行标签,即<tr></tr>标签。

jsonData01 = jsonData01.responses.map((details,index) =>{
     return (
        <tr>
          <td>{details.fullTextAnnotation.text}</td> // check if this data is available
          <td>{details.context.pageNumber}</td>
        </tr>
     )
})

Your error logs indicate that your snippet worked fine (check logs). 您的错误日志表明您的代码片段运行正常(检查日志)。

Your error logs say you've got a <div> inside your <table> (which is as XML "ok" but React considers it as DOM violation for HTML). 您的错误日志说您在<table> <div>内有一个<div> (XML为“ ok”,但React认为它是HTML的DOM违规)。

I see another small mistake in your code: 我在您的代码中看到另一个小错误:


let jsonData01 = data01;
jsonData01.responses.map((details,index) =>{ return jsonData01 = ((details.fullTextAnnotation.text) && (details.context.pageNumber));

Change to 改成

let jsonData01 = data01;
jsonData01 = jsonData01.responses.map((details,index) =>{ return jsonData01 = ((details.fullTextAnnotation.text) && (details.context.pageNumber));

Values vs. References in JavaScript 值与JavaScript中的引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM