我收到此错误,但我认为这与绑定功能有关。
未捕获的TypeError:this.seState不是函数
基本上我有一些我想用单选按钮过滤的数据。
选择特定值的按钮只会导致具有该值的对象作为其属性进行渲染。
import React, { Component } from 'react';
import { Card, Select, Segment, Container, Divider, Grid, Header, Image } from 'semantic-ui-react';
import '../css/app.css';
class FilterOptions extends Component {
constructor(props) {
super(props);
this.state = {
data: this.props.data,
priority: '',
};
this.handleChange = this.handleChange.bind(this);
}
handleChange(e) {
var val = e.target.value;
this.setState({ priority: val });
this.props.changeOption(val);
}
render() {
return (
<div>
<ul>
<li>
<label>
<input type="radio" value="1" checked={this.state.priority === '1'} onChange={this.handleChange} />
1
</label>
</li>
<li>
<label>
<input type="radio" value="2" checked={this.state.priority === '2'} onChange={this.handleChange} />
2
</label>
</li>
<li>
<label>
<input type="radio" value="3" checked={this.state.priority === '3'} onChange={this.handleChange} />
3
</label>
</li>
<li>
<label>
<input type="radio" value="4" checked={this.state.priority === '4'} onChange={this.handleChange} />
4
</label>
</li>
</ul>
</div>
);
}
}
function FilterUsers(props) {
return (
<Container>
<br />
<br />
<Grid columns={3} doubling stackable>
{props.data.map((user) => (
<Grid.Column key={user.name}>
<Segment>
<Card>
<Card.Content>
<Card.Header>
<h2>name: {user.name}</h2>
</Card.Header>
<Card.Meta>
<span className="card__age">age: {user.age}</span>
</Card.Meta>
<Card.Description>priority: {user.priority}</Card.Description>
<Card.Description className="card__catergory">category: {user.category}</Card.Description>
</Card.Content>
</Card>
</Segment>
</Grid.Column>
))}
</Grid>
</Container>
);
}
export default class SortAndFilterForm extends Component {
constructor(props) {
super(props);
this.state = {
data: this.props.data,
priority: '',
};
this.handleChange = this.handleChange.bind(this);
}
handleChange(val) {
this.setState({ priority: val });
// var filteredByPriority = this.props.data.sort((a, b) => a.priority - b.priority);
var filteredByPriority = this.props.data.filter(function(item) {
return item.priority === val;
});
this.seState({ data: filteredByPriority });
console.log(filteredData, val);
}
render() {
return (
<div>
<h1>Sorts</h1>
<FilterOptions data={this.state.data} changeOption={this.handleChange} />
<FilterUsers data={this.state.data} />
</div>
);
}
}
任何帮助将不胜感激!
答案 0 :(得分:1)
从
更改行def standardize(img):
mean = np.mean(img)
std = np.std(img)
img = (img - mean) / std
return img
for img in rgb_images:
r_channel = standardize(img[:,:,0])
g_channel = standardize(img[:,:,1])
b_channel = standardize(img[:,:,2])
normalized_image = np.stack([r_channel, g_channel, b_channel], axis=-1)
standardized_images.append(normalized_image)
standardized_images = np.array(standardized_images)
到
this.seState({ data: filteredByPriority });
答案 1 :(得分:1)
似乎是一个拼写错误。它的this.setState
不是this.seState
。
将其更改为:this.setState({ data: filteredByPriority });