【发布时间】:2016-01-04 07:52:24
【问题描述】:
在 React 中,从 props 中循环遍历数组中的对象时,我使用了 .map。这似乎不适用于 React Native。是不是我写错了?
反应原生道具:
var appObject = {
users:[
{name:'Jack'},
{name:'Jill'}
]
}
在 React Native 组件中:
render(){
this.props.passProps.users.map(function (user, i){
console.log('user: ',user.userName,'i',i);
return (
<Text key={i}>{user.userName}</Text>
);
});
}
passProps来自于在父组件<UsersAdded passProps={this.props}/>调用这个组件
console.log 记录用户名和索引号。但是后来我从父组件那里得到一个错误,说A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object. 但是,取出.map 函数并放入一个简单的<Text>Test</Text> 可以正确呈现。
React Native 中的方法是什么?
【问题讨论】:
-
return this.props.passProps.users.map(function (user, i). 输入'return'关键字。希望它有效。
标签: javascript arrays react-native