Don*_*nna 1 javascript rendering amazon-web-services node.js reactjs
我正在尝试使用React实现搜索.我的逻辑流程有2个问题:
当我正在玩它时,我遇到了错误消息
Uncaught Invariant Violation输入是一个void元素标记,不得拥有
children或使用props.dangerouslySetInnerHTML.
这是我的代码:
import React, { PropTypes } from 'react';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import s from './Home.scss';
import AWS from 'aws-sdk';
var GetTech = React.createClass({
render: function() {
var createItem = function(item) {
var csd = new AWS.CloudSearchDomain({
endpoint: 'mycloudsearch.amazonaws.com',
region: 'us-east-1'
});
var params = {
query: {this.state.text}
}
csd.search(params, function (err, data) {
if (err) console.log(err, err.stack);
else {
console.log(JSON.stringify(data));
}
});
}
return (
{this.props.items.map(crateItem)}
)
}
});
var FilteredTechs = React.createClass({
getInitialState: function() {
return {
text: '',
items: []
};
},
handleChange: function(event) {
console.log(event);
this.setState({
text: event.target.value
});
},
handleSearch: function(event) {
event.preventDefault();
this.setState({
items: this.props.items,
text: ''
});
},
render: function() {
return (
<div>
<form onSubmit={this.handleSearch}>
<input
type="text"
value={this.state.text}
onChange={this.handleChange}
/>
<input type="button">Search</input>
</form>
<GetTech items={this.state.items} />
</div>
);
}
});
function Home({ techs }) {
<FilteredTechs />
}
Home.propTypes = {
techs: PropTypes.arrayOf(PropTypes.shape({
})).isRequired,
};
export default withStyles(Home, s);
Run Code Online (Sandbox Code Playgroud)
我是React的新手.请按照您的意愿告诉我,非常感谢您的提示和意见.非常感谢!
Int*_*ang 12
错误很明显:inputs必须是void元素; 也就是说,他们必须自我关闭.
此语法无效: <input type="button">Search</input>
你想要: <input type="button" value="Search" />
要么: <button>Search</button>
| 归档时间: |
|
| 查看次数: |
6668 次 |
| 最近记录: |