稍後記得把範例的mLab URL與帳號密碼改為你自己的
<TextField
style={{position: 'absolute', top: '50px', left: '15%'}}
hintText="搜尋文章..."
underlineStyle={{borderColor: '#EC407A'}}
onChange={(e) => this.searchArticle(e)}
/>
searchArticle(e) {
if (e.target.value.length < 1){ //如果輸入框空白
axios.get('/getArticle')
.then((res) => {
console.log(res.data);
this.setState({FilterArticles: res.data})
})
return
};
if(e.target.value.length > 20) {
sweetAlert('不可超過20字');
return
};
axios.get(`/articles/title/${e.target.value}`)
.then((res) => {
console.log(res.data);
this.setState({FilterArticles: res.data})
})
}
app.get('/articles/title/:title', (req,res) => {
let re = new RegExp(req.params.title, "g");
Post.find({title: re })
.then(data => {
res.end(JSON.stringify(data))
})
})
socket.on('chatRoomUsers', (res) => {
if(this.state.users !== res.user) {
this.setState({ users: res.user });
};
})
{
Object.keys(users).map(function(objectKey, index) {
let name = users[objectKey].name;
let avatar = users[objectKey].avatar;
return (
<IconButton key={index} tooltip={name}>
<Avatar src={avatar} />
</IconButton>
)
})
}