我正在尝试计算字符串中元音的数量,但我的计数器似乎没有返回多个.有人可以告诉我我的代码有什么问题吗?谢谢!
var vowelCount = function(str){
var count = 0;
for(var i = 0; i < str.length; i++){
if(str[i] == 'a' || str[i] == 'i' || str[i] == 'o' ||str[i] == 'e' ||str[i] == 'u'){
count+=1;
}
}
return count;
}
console.log(vowelCount('aide'));
Run Code Online (Sandbox Code Playgroud) 我正在尝试让 Material-UI 选项卡与路由一起工作,并且当路由正在工作并显示所选选项卡时,在选项卡之间导航的平滑动画不再起作用。如何使用带有 Material-UI 选项卡的 react router 来保持选项卡动画正常工作?
到目前为止,我的 HomeHeader.js 中有选项卡,我正在使用此组件将谷值作为道具传递以更改值,从而更改选定的选项卡。
为简单起见,我简化了代码以显示要链接的选项卡。
这是我的代码:
Header.js(带标签的组件):
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Link } from 'react-router-dom'
class HomeHeader extends Component {
state = {
value: false
};
handleChange = (event, value) => {
this.setState({ value })
};
render() {
const { classes, value } = this.props
return (
<AppBar className={classes.appBar} elevation={this.props.elevation}>
<Hidden smDown>
<Grid container justify="space-between" alignItems="center">
<Tabs value={value} onChange={this.handleChange}>
<Tab label="monitor" component={Link} to="/monitor" /> …Run Code Online (Sandbox Code Playgroud) javascript reactjs react-router material-ui react-router-dom
我无法使KeyboardAvoidingView正常工作.对于类似的屏幕,它工作顺利,但另一方面,它将内容推向屏幕上太远的位置,在两者之间增加了过多的空间.任何修复?
码:
<KeyboardAvoidingView behavior="padding" style={styles.container}>
{this.props.signNameErr &&
(<Text style={{color: 'red'}}>{this.props.errMessage}</Text>)
}
<View style={styles.formContainer}>
<TextInput
style={styles.formInput}
placeholderTextColor="rgba(255,255,255,0.7)"
underlineColorAndroid='rgba(0,0,0,0)'
returnKeyType="next"
autoCorrect={false}
onChangeText={(full_name)=> this.setState({full_name})}
value={this.state.fullname}
placeholder="Enter Full Name"
/>
{this.props.signEmailErr &&
(<Text style={{color: 'red'}}>{this.props.errMessage}</Text>)
}
<TextInput
style={styles.formInput}
placeholderTextColor="rgba(255,255,255,0.7)"
underlineColorAndroid='rgba(0,0,0,0)'
returnKeyType="next"
keyboardType="email-address"
autoCapitalize="none"
autoCorrect={false}
onChangeText={(email)=> this.setState({email})}
value={this.state.email}
placeholder="Enter Email"
keyboardType="email-address"
/>
{this.props.signPwErr &&
(<Text style={{color: 'red'}}>{this.props.errMessage}</Text>)
}
<TextInput
style={styles.formInput}
placeholderTextColor="rgba(255,255,255,0.7)"
underlineColorAndroid='rgba(0,0,0,0)'
returnKeyType="next"
autoCorrect={false}
onChangeText={(password)=> this.setState({password})}
secureTextEntry={this.state.togglePW}
value={this.state.password}
placeholder="Create Password (Min. 6 Char)"
/>
<TouchableOpacity style={styles.buttonContainer} onPress={this.handleSignup}>
<Text style={styles.buttonText}>SIGN UP</Text>
</TouchableOpacity>
</View >
</KeyboardAvoidingView>
Run Code Online (Sandbox Code Playgroud) 在父组件中,当组件安装时,我使用几种样式修改主体:
document.body.style.overflowX = "hidden";
document.body.style.width = "100%";
Run Code Online (Sandbox Code Playgroud)
在我的父组件中是对话框子组件,但是当我打开和关闭对话框时,该overflow属性将被删除,而该width属性仍然保留。为什么?
假设我有两个对象数组:
let array1 = [
{
id: 1,
name: 'snow'
},
{
id: 4,
name: 'jo'
},
{
id: 8,
name: 'bran'
},
{
id: 12,
name: 'gondo'
},
{
id: 13,
name: 'peter'
}
]
let array2 = [
{
id: 3,
name: 'brim'
},
{
id: 4,
name: 'not-jo'
},
{
id: 8,
name: 'not-bran'
},
{
id: 13,
name: 'spleen'
}
]
Run Code Online (Sandbox Code Playgroud)
我想找到array2中与id匹配的所有对象与array1,并更改其名称值以匹配array1中的名称值.
在我的伪代码中:
array1.forEach((person)=> {
if(person.id is equal to person.id in array2){
person.name = person.name in …Run Code Online (Sandbox Code Playgroud) 我正在尝试根据将selectedprop 设置为true或false 来动态设置菜单列表项的样式。
我试图使用该onClick方法并读取event.target.name,更改value每个菜单项提供的状态,然后最终使用selectedprop检查该值是true还是false。由于某种原因,它没有获取event.taget.name我要记录的日志。
上方渲染:
constructor(props) {
super(props);
this.state = {
notFound: false,
value: false,
anchorEl: null,
industry: ''
};
}
handleIndustriesSelect = event => {
this.setState({ [event.target.name]: event.target.value });
console.log('target',event.target.name)
this.handleIndustriesClose()
}
Run Code Online (Sandbox Code Playgroud)
下方渲染
<Menu
id="industries-menu"
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={this.handleIndustriesClose}
MenuListProps={{
name: 'industry'
}}
>
<MenuItem value={'aerospace'} selected={this.state.industry === 'aerospace'} onClick={this.handleIndustriesSelect} component={Link} to='/home/industry/aerospace'>Aerospace</MenuItem>
<MenuItem onClick={this.handleIndustriesSelect} component={Link} to='/home/industry/automotive'>Automotive</MenuItem>
<MenuItem onClick={this.handleIndustriesSelect} component={Link} to='/home/industry/energy'>Energy</MenuItem>
<MenuItem onClick={this.handleIndustriesSelect} component={Link} to='/home/industry/industrial'>Industrial</MenuItem>
<MenuItem onClick={this.handleIndustriesSelect} component={Link} to='/home/industry/marine'>Marine</MenuItem> …Run Code Online (Sandbox Code Playgroud) 我有一个数组中的电子邮件列表:
["gomand@gmail.com", "terry@yahoo.com", "123Yu@gmail.com"]
Run Code Online (Sandbox Code Playgroud)
我如何遍历数组并将每封电子邮件作为自己的属性推送到对象中:对象如下所示:
{
email1: "gomand@gmail.com",
email2: "terry@yahoo.com",
email3: "123Yu@gmail.com"
}
Run Code Online (Sandbox Code Playgroud) 例如,假设我有数字 345。如何在 javascript 中循环遍历数字中的每个数字并将其提高到连续的 n 次方:即 3^1 + 4^2 + 5^3?