对于一个学习项目,我目前正在开发一个移动应用程序,用于在本机 React 中读取 QR 码。扫描 QR 码后,我会将其 id 保存在历史记录中。
当我单击此 ID 时,我想打开一个包含有关此 QR 码的信息的页面(由 API 休息检索)。但是当我选择一个ID时,得到的信息是之前二维码的信息。
我创建了一个更新信息的按钮,但我希望它是正确的。
谢谢,我附上了我的代码和我的项目的 git。
吉特:https ://github.com/davidsio/react
import React, { Component } from 'react';
import { StyleSheet, View, Text} from 'react-native';
import QRCode from 'react-native-qrcode-svg';
let getJSON = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
export default class Informations extends Component {
static navigationOptions = {
title: 'Informations',
headerBackTitle: 'Retour',
headerStyle: {
backgroundColor: '#557aca',
//Sets Header color
},
headerTintColor: '#fff',
//Sets Header text color
headerTitleStyle: {
fontWeight: 'bold',
//Sets Header text style
},
//Sets Header text of Status Bar
};
render() {
const { navigate } = this.props.navigation;
const { params } = this.props.navigation.state;
const itemValue = params ? params.itemValue : null;
const itemId = params ? params.itemId : null;
getJSON('http://elarnes.fr/get_qrcode.php?idQrCode=' + JSON.stringify(itemValue).replace(/['"]+/g, '').split(';')[1],
function(err, data) {
if (err !== null) {
console.log('Something went wrong: ' + err);
} else {
tabCode = data[0]
}
});
饮歌长啸
守着星空守着你
慕婉清6462132
随时随地看视频慕课网APP
相关分类