你好,我正在读这样一个JSON响应对象。
<td className="text-right flex">
{finance.statuses.map((statuses) => {
return statuses.currencyAmounts.map((amounts) => (
<span className="pr-8" key={amounts.currencyId}>{amounts.maxGambleAmount}</span>
));
})}
</td>它工作得很好,但是我需要用索引amounts.currencyId,绑定每个值后面的全局变量数组中的货币缩写--我的问题是不能访问内部映射中的那些货币。
我尝试过类似的currenciesamounts.currencyId,但没有成功。
有人能帮我吗?谢谢
发布于 2020-07-10 15:34:48
根据您的注释,currencies变量存在于您的mapStateToProps函数中。如果有一个mapStateToProps,很可能您将使用redux库。如果是这样的话,我强烈建议你花点时间熟悉它。
--但回到问题--,通常mapStateToProps会返回一个对象,并且这些对象的所有属性都应该在组件的props中可用。如果在您的currencies函数中已经有了可用的mapStateToProps,您可以简单地将它添加到return语句中,如下所示:
function mapStateToProps(state) {
return {
// this should make your "currencies" object/map available in the props of your component:
currencies: state.currencies,
};
}
// In your component you should have the "props" available as the parameter,
// you just have to access it now:
<td className="text-right flex">
{finance.statuses.map((statuses) => {
return statuses.currencyAmounts.map((amounts) => (
<span className="pr-8" key={props.currencies[amounts.currencyId]}>{amounts.maxGambleAmount}</span>
));
})}
</td>https://stackoverflow.com/questions/62836141
复制相似问题