我想将 Django Rest Framework 中的数据显示到 DropDownPicker React-Native ( https://github.com/hossein-zare/react-native-dropdown-picker ) 这是我的代码:
import React, { useState, useEffect } from "react";
import { StyleSheet, View, Text, Image, FlatList, Button, TouchableOpacity } from "react-native";
import client from "./../../api/client";
import DropDownPicker from 'react-native-dropdown-picker';
const Droplo = ({navigation, route}) => {
const [detailha, setDetailha] = useState("");
const [value, setValue] = useState(null);
let controller;
const getDetailha = async (url) => {
try {
const response = await client.get(url);
if (!response.ok) {
setDetailha(response.data);
console.log(response.data)
}
} catch (error) {
console.log(error);
}
};
useEffect(()=>{ getDetailha('/habilidad/'); }, [])
return (
<View>
<DropDownPicker
items={detailha}
controller={instance => controller = instance}
onChangeList={(items, callback) => {
new Promise((resolve, reject) => resolve(setDetailha(items)))
.then(() => callback())
.catch(() => {});
}}
defaultValue={value}
onChangeItem={item => setValue(item.nombre_habilidad)}
/>
</View>
);
}
export default Droplo;
数据是:
错误是:
谢谢你!