作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 React 实现搜索。我的逻辑流程有 2 个问题:
我在玩的时候遇到了错误信息
Uncaught Invariant Violation input is a void element tag and must not have
children
or useprops.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);
我是 React 的新手。请按照您的意愿告诉我,非常感谢您的提示和评论。非常感谢!
最佳答案
错误很明显:input
s 必须是空元素;也就是说,它们必须是自动关闭的。
此语法无效:<input type="button">Search</input>
您想要:<input type="button" value="Search" />
或:<button>Search</button>
关于javascript - 渲染搜索数据时未捕获的不变违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36526061/
在我们的数据库表上,我们使用两个唯一的非聚集索引来创建跨四个字段的唯一约束。我们使用两个,因为其中一个字段 ZipCode 是一个可为空的字段。如果表中存在一条包含 ZipCode 的 null 条目
我刚刚开始学习 Rails 3 教程,以便对框架有一点熟悉,但我在生成 schema.rb 时遇到了问题。我的操作系统是 Windows 7 x64、Ruby 1.9.2、MySQL2 gem 0.2
我是一名优秀的程序员,十分优秀!