呈现搜索数据时出现未捕获的不变冲突
Uncaught Invariant Violation on rendering search data
我正在尝试使用React实现搜索。我的逻辑流程有两个问题:
- 将输入设置为参数
- 渲染我从服务器获得的数据
当我玩它时,我遇到了错误消息
Uncaught Invariant Violation输入是void元素标记,不能具有CCD_ 1或使用CCD_。
这是我的代码:
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);
我是React的新手。请按你的意愿给我建议,非常感谢你的建议和意见。非常感谢!
错误非常明显:input
s必须是void元素;也就是说,它们必须是自我封闭的。
此语法无效:<input type="button">Search</input>
您想要任一:<input type="button" value="Search" />
或者:<button>Search</button>
输入是自关闭标记,但是在某些情况下可以使用<Input></Input>
您可以安装reactstrap包,然后导入并使用<Input></Input>
标记,而不是使用<input></input>
。此外,您还可以查看链接:https://reactstrap.github.io/components/input-group/此外,您还可以检查输入类型:reactstrap Forms
相关文章:
- 用程序搜索JQuery数据表中的文本
- 在html Select中添加搜索
- Ajax Live搜索发布到Laravel视图
- 谷歌放置API:按国家或餐馆名称搜索餐馆
- 学生搜索项目jquery/javascript
- 用于搜索的聚合物嵌套绑定
- 在javascript中搜索具有重复值的两个数组中的匹配值
- Angularjs-utils高亮过滤器在搜索时破坏应用程序
- 使用javascript搜索具有用户输入的数组
- 淘汰搜索/筛选
- 搜索api在mac上显示对话框
- Javascript-ID冲突的几率
- AngularJS/HTML/Bootstrap元素用于动态搜索结果
- 谷歌水印未显示在自定义搜索框中
- 在javascript中搜索项目列表的性能
- 覆盖与查询实时搜索冲突
- 呈现搜索数据时出现未捕获的不变冲突
- JQuery版本与Div搜索效果冲突
- 日历和快速搜索的 Jquery 冲突问题
- mm菜单&prototype.js冲突,html在使用搜索字段时消失