javascript - react/redux 中组件显示两次
问题描述
函数 1 返回 JSON 数组。
function allPlans()
{
var all_plans = {
'Option1' : {
'free':{status:true,plantext:"5 Per Month"},
'premium':{status:true,plantext:"Unlimited"},
'vip':{status:true,plantext:"5 Per Month"}
},
'Option2' : {
'free':{status:true,plantext:"Unlimited"},
'premium':{status:true,plantext:"Unlimited"},
'vip':{status:true,plantext:"Unlimited"}
},
'Option3' : {
'free':{status:true,plantext:"Unlimited"},
'premium':{status:true,plantext:"Unlimited"},
'vip':{status:true,plantext:"Unlimited"}
},
'Option4':{
'free':{status:true,plantext:"-"},
'premium':{status:true,plantext:"Full Access"},
'vip':{status:true,plantext:"Full Access"}
},
'Option5' : {
'free':{status:true,plantext:"-"},
'premium':{status:true,plantext:"3 Per Month"},
'vip':{status:true,plantext:"3 Per Month"}
},
'Option6' : {
'free':{status:true,plantext:"-"},
'premium':{status:true,plantext:"-"},
'vip':{status:true,plantext:"1 Portfolio"}
},
'Option7' : {
'free':{status:true,plantext:"-"},
'premium':{status:true,plantext:"-"},
'vip':{status:true,plantext:"1 Per Month"}
},
}
return all_plans;
}
另一个函数“rendercolumn()”返回计划视图。
function rendercolumn()
{
const options = allPlans();
var isrowclass = false;
var getrowclass = "";
const plansMap = Object.keys(options).reduce((acc, title) => {
if (props.planname == 'free')
{
var plans = options[title]["free"];
}
else if(props.planname == 'premium')
{
var plans = options[title]["premium"];
}
else if(props.planname == 'vip')
{
var plans = options[title]["vip"];
}
Object.keys(plans).forEach(plan =>
{
if (!acc[plan])
{
acc[plan] = [];
}
if(isrowclass == true)
{
isrowclass = false;
getrowclass = plan_item_gray;
}
else
{
isrowclass = true;
getrowclass = plan_item;
}
acc[plan].push({
title,
status: plans.status,
text: plans.plantext,
rowclass: getrowclass,
})
});
return acc;
}, {})
return (
<div>
{Object.keys(plansMap).map(plan => (
<Column key={plan} data={plansMap[plan]} />
))}
</div>
)
}
之后称为组件“列”
const Column = ({data}) => (
<div>
{data.map(option => (
<div className={option.rowclass}>{option.text}</div>
))}
</div>
)
最后我调用了“{rendercolumn()}”函数来显示视图上的数据。
现在在上面的所有代码中,我得到了预期的行,但它显示了两次细节。
我得到的结果如下:
我想要这样的结果:
上面的代码需要做哪些改动?
解决方案
推荐阅读
- ruby - 使用 cygwin 和 Visual Studio 代码在 Windows 中调试 ruby
- python-3.x - 在 Django 中使用内联保存模型
- javascript - 在迭代 JSON 数组时出现错误:“data.id is undefined”
- ssh - 使用 JMeter 中的 OS Process Sampler 将文件从一个 Windows 远程服务器传输到另一个 Windows 远程服务器的步骤
- c# - 语音合成器阅读不适用于专有名词(文本到语音)
- python - Django get_user_model().objects.create() 密码没有得到散列
- python - 使用 zeromq 在 2 个 python 程序之间交换信息
- shell - 如何使用 sh 在 groovy 中执行 repo forall project -c 'echo $REPO_PATH',因为 REPO_PATH 是 repo 工具内部的变量
- javascript - 如何显示加法操作?
- python - 将 TF 模型从 py2 移植到 py3