如何解决如何让for循环完成
我有一个对象,用于在启动画面关闭后在加载时添加工具提示。该对象看起来像这样:
layerNameMapping =
{
"samp_bldgs": {"title": "Sample_Bldgs","index": 0,"tt": "Approximate center of buildings within BLE areas","visible": false},"buildings": { "title": "Buildings","index": 1,"visible": true},"buildings_risk_chng": { "title": "Buildings Risk Change","index": 2,"tt": "Color-coded change of building from effective flood hazard to BLE","contours": { "title": "Contours","index": 3,"tt": "2ft contour lines","contours_diced": { "title": "Contours_Diced","index": 4,"modeled_streamline": { "title": "Modeled Streamline","index": 5,"tt": "Modeled stream centerlines for BLE studies","counties": { "title": "Counties","index": 6,"tt": "County boundaries",....
}
基本上,代码使用 jQuery
遍历 node selector
对象中的项目,有一个函数 (tooltipper2
) 来根据 item.title
检查每个项目{1}}。加载时,主节点选择器(名为 layerNameMapping
的变量)中将始终有 4 个项目。
baseElement_map
我的目标是遍历加载时的 4 个项目中的每一个(同时 $(window).load(function () {
$('#myDisclaimerModal').modal('show');
function tooltipper2(name) {
var lyr_map = layerNameMapping;
var size = Object.keys(lyr_map).length;
tt = name;
for (i = 0; i < size; i++) {
if (lyr_map[Object.keys(lyr_map)[i]].title === name) {
tt = lyr_map[Object.keys(lyr_map)[i]].tt;
}
}
return tt;
}
$('#splash_close_btn').on("click",function () {
switcher = true;
window.setTimeout(function () {
var baseElement_map = document.querySelector('div.esri-legend').querySelectorAll('div.esri-legend__layer-caption');
if (baseElement_map) {
for (i = 0; i < baseElement_map.length; i++) {
layerName = baseElement_map[i].innerHTML;
baseElement_map[i].title = tooltipper2(layerName);
}
}
},500);
});
});
),将项目标题与 i < 4
对象中的标题匹配,并将节点项目的标题替换为 tt (对于“工具提示”)。这有效,但仅适用于第一项。在通过第一个节点 item.title ("Modeled Streamline") 后,它在控制台中调试时中断并且永远不会移动到下一个项目。关于我在这里做错了什么的任何想法?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。