简体   繁体   English

在 React-Native 二维码列出的信息前面写

[英]Writing in front of the information listed in the React-Native QR Code

This is my code where I print the information in the QR Code to the screen.I put a space after each '@' sign.这是我的代码,我将二维码中的信息打印到屏幕上。我在每个“@”符号后放置一个空格。 I want to add a comment before each of these listed lines.我想在列出的每一行之前添加评论。

 const Scanned = ({ route }) => { const { data } = route.params; const filter = data.replace(/@/g, `\n`);

I hope this will help you我希望这能帮到您

 const Scanned = ({ route }) => { // const { data } = route.params; const [qrText, setQrText] = React.useState(""); React.useEffect(() => { const data = '@Red@Pros@42@1$'.split('@'); // use data from route.params const labels = ['Color', 'Shape', 'Weight', 'Price']; let text = data.map((item, i) => (item ? `${labels[i]}:${item}` : item)); text = text.join('\n'); setQrText(text); }, []); return ( <pre>{qrText}</pre> ) }; ReactDOM.render( <Scanned/>, document.getElementById('root') );
 <script src="https://unpkg.com/react@16.7.0-alpha.0/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@16.7.0-alpha.0/umd/react-dom.development.js"></script> <div id="root"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM