Javascript二“;对于“;循环从3个数组中获取数据
Javascript two "For" cycle loop to get data from 3 arrays
我有三个数组——一个标题数组有10个元素,第二个字幕数组有121个元素,而第三个描述数组有121元素,我需要在列表中显示它,我把它放在下面的格式中:
---Title
---subtitle[0]----listequivalent[0]
----subtitle[1]-----list equivalent[1]
---subtitle..etc
---------------------
----title 2
---- subtitleofthis[2]-----descriptionEquivalent[2]
----subtitleofthis[3]-----descriotionEquivalent[3] subtitleofthis...etc
---------------------
我有这个:
for(var j=0;j<titles.length;j++){
$("#divisionTitles").append("<div class='content-block-title'>" + titles[j] + "</div>");
for(var i=0;i<subtitle.length;i++){
$("#divisionTitles").append(" <ul>"+
"<li class='item-link item-content'>"+
" <a href='=" + description[i] +"'" + ">"+
"<div class='item-inner'>"+
"<div class='item-title'>"+ subtitle[i] +"</div>"+
"</div>"+
"</a>"+
"</li>"+
"</ul>");
}
}
但它显示为:
---title
---subtitle[all] //all from 1 to 121 with the descriptions 1 to 121
--- title 2
--- subtitle[all] //all from 1 to 121 with the descriptions 1 to 121
因为这正是你告诉它要做的——将它"翻译"成更人性化的语言,所以它看起来像:
for each title print all the subtitles
你需要像这样的东西
fore each title print all the MATCHING subtitles
这意味着你必须稍微改变一下你的结构(例如,有一个数组,这个数组的每个元素都是包含title
的对象,另一个数组包含每个匹配的字幕)
或者,如果你出于某种原因需要保留你的结构,你可以这样做:
for each title do following:
read all the subtitles and if it's matching print it
这意味着你将在你的内部for
中添加一个if
,这意味着它看起来像这样:
for(var j=0;j<titles.length;j++){
$("#divisionTitles").append("<div class='content-block-title'>" + titles[j] + "</div>");
for(var i=0;i<subtitle.length;i++){
if(subtitle is matching) {
/* I don't know how the code should find out which
* title does this subtitle matching because of this
* i'm not putting exact code in the if but only a psedocode
*/
/*** do your stuff here ***/
}
}
}
相关文章:
- 从json子数组获取数据
- 从javascript数组获取php的日期时间
- 从表中的 JSON 数组获取数据
- 每个表的2D数组获取坐标JTSL,JAVASCRIPT
- javascript从元素到数组获取文本
- 如何从数组获取链接以在youtube Iframe API中播放
- JSON 编码多维数组获取值
- 如何从两个 JSON 数组获取增量
- 通过单击按钮数组获取隐藏 html 元素值的当前数组
- 在 JavaScript 中从内部数组获取数据
- 从数组获取非重复索引在 0 时失败
- JavaScript 从对象中的数组获取数组
- 如何通过 ajax 将 php 数组作为 javascript 数组获取
- 快速从 2D 数组获取索引,无需迭代 jquery
- 从 Nodejs socketio 数组获取所有套接字 id
- 无法动态从 json 数组获取数据
- 如何在javascript中使用数组获取和设置html标签的值
- jQuery对象数组获取一个项作为jQuery对象
- 如何在不向输出数组获取空值的情况下拆分字符串
- 从输入到数组获取数据