react-native - React Native RNPicker 选择
问题描述
我正在使用 RNPicker Select,我希望从 api 获取下拉项目,但我得到空的下拉列表,没有值以下是我的代码
class Component extends Component {
constructor(props) {
super(props);
this.state = {
inqSourceList: [],
}
componentDidMount() {
this.fetchSource();
}
fetchSource = () => {
getInqSourceList('view=select', this, null)
}
<RNPickerSelect
items={this.state.inqSourceList}
name="source"
value={this.state.source ? this.state.source.id : null}
onValueChange={value => {
this.setState({
source:value,
});
}}
style={{marginBottom: 10}}
/>
我的api代码是
export async function getModuleList (moduleName, params,error) {
let token = await AsyncStorage.getItem('token');
axios
.get(BASE_URL + moduleName + "?" + params, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: "Bearer " + token },
})
.then((res) => {
var bytes = CryptoJS.AES.decrypt(res.data.toString(), ENCDEC);
res.data = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
// success(res.data);
// console.log(res.data)
})
.catch(error);
}
在这个我使用console.log(res.data)时从后端获取值我得到选项列表..但是下拉项目是空的..谢谢
这是设置 inqSourceList 的函数
export function getInqSourceList(params, _this, next) {
getModuleList('settings/inquiry-source', params, data => {
_this.setState({inqSourceList: data.rows});
if (next) next(data);
});
}
解决方案
推荐阅读
- python - 使用python将简单矩阵转换为关联矩阵
- swift - Xcode 中 SwiftUI 中的分段 11 非零退出代码错误
- xml - 如何解决此项目构建错误:不可解析的 POM 错误?
- javascript - 很难处理由“导入”引起的错误
- django - localhost:8000 和 http://127.0.0.1:8000 有什么区别?
- javascript - 如何将一个数字映射到 1,这样 number/2 === 0.5 等等?
- javascript - 在 Node.js/Express 中等待后端数据库更新后如何更新前端?
- mysql - mySql - 在第二个表中搜索没有引用的行
- azure-devops - 在 Azure DevOps 门户中,如何查询今天已修改完成工作的任务列表
- php - (PHP + MySQL)如何显示灰色禁用的字段在使用只读时仍然可以提交数据