javascript - 我的价值越来越在观看结束时做出反应
问题描述
当代码完成时,cData 的值变空,当我在它之间进行调试时,它会获取数据
const FsAccount = React.memo(() => {
let cData: any;
const accountData = useSelector((state: any) => {
let tempData = state.account.customerDataByAccount;
// tempData = JSON.stringify(tempData)
let final: any = [];
tempData.forEach((el: any) => {
Object.keys(el).forEach((key) => {
let values: any = [];
Object.entries(el[key][0]).forEach((entry) => {
values.push({ title: entry[0], value: entry[1] });
});
let newElement: any = {};
newElement[key] = values;
final.push(newElement);
final.map((el: any) => {
if (el.Consumer) {
cData = el.Consumer; // here it should have el.Consumer but after execution its getting empty
}
});
});
});
console.log("state :>> ", cData);
});
});
.......
我也在 el.Consumer 中获取数据,当我在控制台中观看它时,它获取了数据,但最后它显示我在监视 cData
解决方案
在动作文件中试试这个而不是在这里做
let tempData = state.account.customerDataByAccount;
// tempData = JSON.stringify(tempData)
let final: any = [];
tempData.forEach((el: any) => {
Object.keys(el).forEach((key) => {
let values: any = [];
Object.entries(el[key][0]).forEach((entry) => {
values.push({ title: entry[0], value: entry[1] });
});
let newElement: any = {};
newElement[key] = values;
final.push(newElement);
final.map((el: any) => {
if (el.Consumer) {
cData = el.Consumer; // here it should have el.Consumer but after execution its getting empty
}
});
});
});
而不是 tempData 使用带有您想要的索引的响应。
推荐阅读
- .net-core - 在 HeroCard 中发送 CardActions 作为欢迎信息并直接进入相应的对话框
- .net-core - 如何在同一个项目中创建具有 Angular7 + WebAPI + AzureAD 的 .NET Core 应用程序
- python - 如何将 Ansible 模块 wait_for 与循环一起使用?
- php - PHP foreach 没有遍历嵌套数组
- c# - 将 FeedOptions.EnableCrossPartitionQuery 设置为 false 是否需要与 FeedOptions.PartitionKey 结合使用?
- ruby - 如何在 Ruby 中对本地应用程序进行 x-callback-url 调用?
- json - JSONPath 正则表达式 - 不以
- sql - 派生列表达式
- python - Python opencv检测棋盘
- html - 如何将多个连接的 .html 文件一起作为网站打开?