【发布时间】:2021-07-01 13:01:31
【问题描述】:
当包含在数组中的相应匹配 JS 对象的“实时”值为 true 时,我无法弄清楚如何正确定位和显示 HTML id 标记。
我希望 JS 循环仅在链接 id 与对象的“scheduleId”匹配并且该对象的“live”值为真时才在调度模块中显示链接。我将如何定位和显示此链接?
在这里查看我的 HTML:
<div class="test-schedule">
<h2>Schedule</h2>
<div><span>School of Ed</span><a class="link-class" id="ed">School of Ed link</a></div>
<div><span>School of Humanities</span><a class="link-class" id="hss">School of Humanities link</a></div>
<div><span>School of Science</span><a class="link-class" id="sci">School of Science link</a></div>
<div><span>School of Nursing</span><a class="link-class" id="nursing">School of Nursing link</a></div>
</div>
<style>
.link-class{display:none}
</style>
这里是JS:
const eventList = [
{
scheduleId: 'ed',
live: 'true',
},
{
scheduleId: 'hss',
live: 'false',
},
{
scheduleId: 'sci',
live: 'false',
},
{
scheduleId: 'nursing',
live: 'false',
},
];
Codepen 链接: https://codepen.io/lvl12sealclubber/pen/PoWbJZQ?editors=1011
【问题讨论】:
-
我不明白你的问题..不清楚
-
感谢@Frenchy,我已经修改了我的帖子以帮助澄清。
标签: javascript arrays json sorting object