【发布时间】:2020-02-19 21:48:00
【问题描述】:
因此,我正在构建其中一款天气应用程序,其中包含基于天气状况的自定义报价。下面的代码有效......但如您所见,我有多个引号。我生成了一个随机数变量,它也有效。我正在尝试将该变量添加到weatherCases JSX...我知道可以做到,但是伙计,我无法弄清楚使其工作的语法...
报价工作
const weatherCases = {
"clear sky": {
title: "clear sky",
quote1: "Custom quote 1.",
quote2: "Custome quote 2",
quote3: "Custom quote 3",
...
}
}
function Forecast({ temp, weatherName, city }) {
return (
<View style={styles.forecastContainer}>
<View style={styles.forecastTopContainer}>
<View>
<Text style={styles.quoteText} >{weatherCases[weatherName].quote}</Text>
</View>
</View>
</View>
);
}
我正在尝试获取随机引用(这是使该行正常工作的十几个编辑之一:
function Forecast({ temp, weatherName, city }) {
const randomNumber = (Math.floor(Math.random() * 30));
console.log(randomNumber);
//console.log(weatherName);
return (
<View style={styles.forecastContainer}>
<View style={styles.forecastTopContainer}>
<View>
<Text style={styles.quoteText} >{weatherCases[weatherName].quote.{randomNumber}}</Text>
</View>
</View>
</View>
);
}
【问题讨论】:
标签: json react-native jsx