我想根据用户选择的播放器的数量来制作字段列表.我想做这样的事情:
generatePaymentField() {
var noGuest = this.state.guest;
var payment =
<View>
<View>
<View><Text>No</Text></View>
<View><Text>Name</Text></View>
<View><Text>Preference</Text></View>
</View>;
for (var i=0; i < noGuest; i++) {
payment = payment +
<View>
<View>
<TextInput />
</View>
<View>
<TextInput />
</View>
<View>
<TextInput />
</View>
</View>;
}
return payment;
}
render () {
var payment = this.generatePaymentField();
this.setState({payment : payment});
return (
<View>
{this.state.payment}
</View>;
)
}
Run Code Online (Sandbox Code Playgroud)
但react-native将上面的语法视为指向for循环行的"意外令牌".有没有其他方法可以实现这一目标?
我正在使用RN 0.20 for iOS.我想建立一个链接,如果您点击该链接,它会将您的坐标重定向到手机中可用的地图应用.这就是我使用Linking组件所做的.
redirectToMap() {
Linking.canOpenURL('geo:37.484847,-122.148386').then(supported => {
if (supported) {
Linking.openURL('geo:37.484847,-122.148386');
} else {
console.log('Don\'t know how to go');
}
}).catch(err => console.error('An error occurred', err));
}
Run Code Online (Sandbox Code Playgroud)
但它不断给我'不知道怎么去'.但是,我从其https://facebook.github.io/react-native/docs/linking.html中的文档中看到,它可以geo:
用于链接到地图.
我目前正在为Android项目使用React-Native.我一直在尝试在字段旁边创建一个带有图标的TextInput字段.但是,由于某些原因,我注意到flexDirection: 'row'
如果TextInput是其子组件之一,则无效.我应用该样式的整个视图将自动消失.这是我的代码如下所示的片段:
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<View style={{flexDirection: 'row'}}>
<Image
style={{height: 30, width: 30}}
source={require('./images/email-white.png')}
/>
<TextInput
style={{height: 40}}
underlineColorAndroid={'transparent'}
placeholder={'E-mail'}
placeholderTextColor={'white'}
onChangeText={(data) => this.setState({ username: data })} />
</View>
</View>
Run Code Online (Sandbox Code Playgroud)
我还试图在每个单独的视图中包含两个组件,但问题仍然存在.有谁知道如何解决这个问题?或者任何人都可以确认这是一个错误?