gpt4 book ai didi

javascript - TypeError undefined 不是一个函数

转载 作者:行者123 更新时间:2023-12-03 01:22:43 24 4
gpt4 key购买 nike

我是 React Native 的新手,我正在尝试使用 map 函数而不是 map 函数创建一个模式。

我不知道这是否是最好的方法,但我查看了很多资源,但不知道如何解决这个问题,因为我总是在标题上遇到此错误:

代码:

let times = this.state.plantelData.map(function (nome, key) {
var detScout = '';
detScout = nome.scout.map(function (item, i) {
return (
<Text>{i + ": " + item} </Text>
)
});
return (
<View style={styles.container} >
<Modal visible={this.state.showMe} onRequestClose={() => console.warn("this is sparta")} >
<View style={styles.modalView} >
{detScout}
<TouchableOpacity onPress={() => {
this.setState({ showMe: false })
}} >
<Text style={styles.closeText}> Fechar</Text>
</TouchableOpacity>
</View>
</Modal>
<ListItem avatar key={key}>
<Left>
<Thumbnail source={{ uri: nome.foto }} />
</Left>
<Body>
<Text>{nome.apelido + " - " + nome.nome_clube + " #" + nome.posicao_clube}</Text>
<Text note>{"Posição: " + nome.posicao_atleta + " - Pontos: " + nome.pontos}</Text>
</Body>
<Right>
<Text note>{nome.pontos}</Text>
</Right>
<Right>
<TouchableOpacity onPress={() => {
this.setState({ showMe: true })
}} >
<Icon type="FontAwesome" name="soccer-ball-o" />
</TouchableOpacity>
</Right>
</ListItem>
</View>
)

Print of error

最佳答案

map()Array.prototype 上的一个方法,但是nome.scout似乎不是一个数组,而是一个普通对象。
您需要的是该对象的键值对,以便您可以映射它们。这可以通过 Object.entries() 来完成.

试试这个:

detScout = Object.entries(nome.scout).map(function([ key, item ]) {
return (
<Text>{key + ": " + item} </Text>
)
});

关于javascript - TypeError undefined 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51696731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com