react-native - 推送联系人列表并渲染一个包含联系人姓名和号码的组件
问题描述
我正在尝试向我的呼叫应用程序呈现联系人列表,但遇到了一些问题('找不到变量:人')。该组件将仅呈现联系人全名和联系人电话号码。
这是我的代码:
import {View, Text} from "react-native";
import Contacts from 'react-native-contacts';
class ContactScreen extends Component {
constructor(props) {
super(props);
this.state = {
ContactsList: ''
};
}
componentDidMount(){
Contacts.getAll((ContactsList) => {this.setState({ContactsList})})
}
render() {
return (
<View style={{justifyContent: 'center'}}>
this.state.ContactsList.map((person) =>
<Text>person.givenName + person.familyName</Text>
<Text>person.phoneNumbers[0].number</Text>
)
</View>
)
}
}
解决方案
Just fixing some syntax below.
import {View, Text} from "react-native";
import Contacts from 'react-native-contacts';
class ContactScreen extends Component {
constructor(props) {
super(props);
this.state = {
ContactsList: ''
};
}
componentDidMount(){
Contacts.getAll((ContactsList) => {this.setState({ContactsList})})
}
render() {
const { ContactsList } = this.state
let contacts = []
if (ContactsList) {
ContactsList.map((person, i) => {
contacts.push(
<View key={i}>
<Text>{person.givenName + person.familyName}</Text>
<Text>{person.phoneNumbers[0].number}</Text>
<View>
)
}
}
return (
<View style={{justifyContent: 'center'}}>
{contacts}
</View>
)
}
}
推荐阅读
- c++ - 在 lua 中使用 require 后全局变量丢失
- angular - Angular中的ngStyle背景图像
- javascript - Drupal 8 搜索模块
- javascript - 从 div 数组中获取所有输入
- c# - 你知道在holo下构建时如何解决这个问题吗?CS0234
- typescript - 在打字稿中没有正确检查条件/三元结果?
- c# - 在 ASP.Net 中使用 Web 服务,不工作
- javascript - 将参数添加到函数以仅在值与数组中的名称匹配时执行
- aws-lambda - 将 SQS Lambda 批处理拆分为部分成功/部分失败
- php - MySQL 查询在晚上没有返回结果,也没有抛出错误