reactjs - 如何在 React Native 中列出传入的数据
问题描述
我想列出示例中使用的服务中的数据。你能帮助我吗?
我的代码:
import React, { Component } from "react";
export default class CustomersTab extends Component {
constructor(props) {
super(props);
this.state = {
token: "",
isLoading: true,
dataSource: null
};
}
componentWillMount() {
tokenner()
.then(responseJson => {
const token = "Bearer " + responseJson.result.token;
this.setState({ token });
fetch(
"apiurl",
{
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: token
}
}
)
.then(response => response.json())
.then(responseData => {
this.setState({
isLoading: false,
dataSource: responseData.result
});
});
})
.catch(error => console.warn(error));
}};
render() {
return (
<View>
<Text>
I WANT LİST DATA HERE
</Text>
</View> )}}
我试着自己做,但我无法建立循环结构。每次只显示一个数据。我应该怎么办?
解决方案
你必须做这样的事情。将 id 更改为您要显示的内容。
return (
<View>
<ListView
dataSource={this.state.dataSource}
renderRow={data => <Text>{data.id}</Text>}
/>
</View>
);
推荐阅读
- javascript - localStorage is null, but only from one function and not another
- python - Python in Visual Studio - Math doesn't work
- typo3 - Assign register value to TYPO3 CASE key
- bash - insert hosts in check via for loop
- php - Not getting id from URL in Laravel 6
- android - 了解 Kotlin 中的顶级 get()
- node.js - 嘿,伙计们,当我尝试运行以下命令时,出现错误“只能使用 'esModuleInterop' 标志默认导入”
- c# - Unity 尝试使用 Color.RBGtoHSV 从获取像素中获取色调,但 H 始终返回 0
- java - IntelliJ VCS ui 问题我该如何解决?
- git - 后面提交的 MR 很危险?