【发布时间】:2022-01-10 08:27:28
【问题描述】:
朋友们好,
我只是从 react-native 开始为 android cel 创建一个应用程序。 我有一个包含 2 个字段 / 的表单,我想从我从 php 文件中提取的 json 加载这些字段。 如果我只通过 json 发送一个值,我可以使用“componentDidMount”和“XMLHttpRequest()”将该值加载到一个字段中 这是我在 componentdidmount 使用的代码:
componentDidMount=()=> {
let _this= this;
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200){
console.log(this.responseText);
var temp = JSON.parse(xhttp.responseText);
console.log(temp);
_this.setState({datos: temp});
}
};
xhttp.open('GET', 'https://smppage.000webhostapp.com/gest_ObtFolio2.php', true);
xhttp.send();
}
这些是 console.log 中打印的值: 响应文本: 日志 [{"iddeOS":"13"},{"fecha":"2021-12-04"}] 温度: 日志 [{"iddeOS": "13"}, {"fecha": "2021-12-04"}]
当我只通过 json 发送一个字段时,我可以将它加载到一个字段中,但我想通过 json 发送 2 个字段,这是我通过 json 仅发送一个字段的值: 响应文本: 记录“14” 温度: 日志 14 这是我在一个 / 中使用的代码,当我只拉一个字段并且该字段正确加载到我的
<View style={{flex:1}}>
<Input
ref={component => this.folioOrden = component}
label=" Folio"
value={this.state.datos.toString()}
使用此代码,它可以正确地将值加载到一个字段中
你能帮忙找到代码来同时填充组件“Folio”和“Fecha”这两个字段吗?
<View style={{flex:1}}>
<Input
ref={component => this.folioOrden = component}
label=" Folio"
value={this.state.datos.toString()}
<View style={{flex:2}}>
<Input
ref={component => this.fechaAperOrden = component}
label=" Fecha"
我已经尝试发送 2 个字段并在两个输入中使用此代码,但我显示错误:
value={this.state.datos.iddeOS.toString()}
value={this.state.datos.fecha.toString()}
提前致谢
【问题讨论】:
标签: json react-native