Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从JSON对象读取嵌套映射时如何使用全局值_Json_Reactjs_Typescript_Dictionary_Nested - Fatal编程技术网

从JSON对象读取嵌套映射时如何使用全局值

从JSON对象读取嵌套映射时如何使用全局值,json,reactjs,typescript,dictionary,nested,Json,Reactjs,Typescript,Dictionary,Nested,您好,我正在阅读这样一个JSON响应对象 <td className="text-right flex"> {finance.statuses.map((statuses) => { return statuses.currencyAmounts.map((amounts) => ( <span className="pr-8" key={amounts.currencyId}>{am

您好,我正在阅读这样一个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>

{finance.statuses.map((statuses)=>{
返回状态.currencyAmounts.map((金额)=>(
{amounts.maxAmount}
));
})}
它工作正常,但我需要在每个值后面绑定一个全局变量数组中的货币缩写,并使用索引amounts.currencyId,我的问题是无法在内部映射中访问这些货币

我尝试了类似于[amounts.currencyId]的方法,但没有成功


有人能帮我吗?谢谢

根据您的评论,您的
货币
变量出现在
MapStateTrops
函数中。如果存在
mapstatetops
,则很可能您将使用
redux
库。如果是这样的话,我强烈建议你花点时间熟悉它

但是回到您的问题,通常
MapStateTrops
会返回一个对象,并且该对象的所有属性都应该在组件的
道具中可用。
如果在
mapstatetops
函数中已经有了
货币
,只需将其添加到return语句中即可,如下所示:

函数MapStateTops(状态){
返回{
//这将使您的“货币”对象/地图在组件的道具中可用:
货币:国家货币,
};
}
//在您的组件中,您应该有可用的“道具”作为参数,
//您现在只需访问它:
{finance.statuses.map((statuses)=>{
返回状态.currencyAmounts.map((金额)=>(
{amounts.maxAmount}
));
})}

您是否真的希望“货币”在全球公开,或者您是否能够
将其导入当前文件中?如果不要求全局可用,只需打开
货币
定义所在的文件,并确保导出变量(通过
导出
),然后只需将其导入当前文件。TS文档:货币位于mapStateToProps中