I am trying to return some html
label when write render
in my component. Code like this:
import React, {Component} from 'react';
import Request from 'react-http-request';
class NameForm extends React.Component {
constructor() {
super();
this.state = {value: '', result: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
var content = this.state.value;
var split = content.split(/\s+/);
var queryObject = new Object();
queryObject.law = null;
queryObject.character = null;
queryObject.lawRule = null;
if (split.length == 1) {
queryObject.law = split[0];
}
else if (split.length == 2) {
queryObject.law = split[0];
queryObject.character = split[1];
}
else if (split.length > 2) {
queryObject.law = split[0];
queryObject.character = split[1];
queryObject.lawRule = split[2];
}
// var json = JSON.stringify(queryObject);
var json = "{\"law\":\"军工企业股份制改造实施暂行办法\",\"character\":\"第二章\"}";
var test = JSON.stringify(<Fetchs args={json}/>);
var request = new XMLHttpRequest();
request.open('POST', 'http://localhost:8080/path', false);
request.setRequestHeader('Content-Type', 'application/json');
var resp = '';
request.onreadystatechange = function (e) {
if (this.status == 200) {
resp = this.response;
}
}
request.send(json);
// console.info("XMLHttpRequest test is " + JSON.stringify(resp));
// console.info("test is " + resp);
this.setState({result: resp});
event.preventDefault();
}
render() {
// console.log("prite"+this.state.result.queryResults);
// console.log("100"+this.strToJson(this.state.result));
// console.log("200"+this.strToJson(this.state.result.queryResults));
// alert(this.state.result);
var parse = JSON.parse(this.state.result ? this.state.result : null);
var out = parse ? parse.queryResults : null;
for (var i = 0; out != null && i < out.length; i++) {
if (out[i].keyword == null) {
out[i].keyword = "{}";
console.info("keyword is null");
}
else {
// this.state.result.queryResults.keyword
console.info("keword is not null");
out[i].keyword = JSON.stringify(out[i].keyword);
}
}
return (
<div>
<form onSubmit={this.handleSubmit}>
<label>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange}/>
</label>
<input type="submit" value="Submit"/>
</form>
<table border="10" >
<tr>
<thead>
<th>GraphName</th>
<th>Relation</th>
<th>Content</th>
<th>KeyWord</th>
</thead>
</tr>
<tbody>
{out}
</tbody>
</table>
</div>
);
}
}
ReactDOM.render(<NameForm/>, document.getElementById('react'))
out
is a array parsed from json data, like this:
My problem is that I want show out
on page by table
label, But use {out}
I get a error, like this:
What troubled me is how to show out
array in a table.
In the minified production build of React, they avoid sending down full error messages. Instead, we can use the error code to view the full message for full errors and additional helpful warnings. This small tool is meant to mitigate this gap.
The calendar does not render and throws the Minified React error #130, which equates to: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed. Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
I believe your trouble maybe caused by the fact that you try to return array of objects in your react render method, instead try to map your objects and insert necessary fields in <p></p>
tags.
For example:
out.map(
(object) => <p>object.content</p>
)
etc... Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With