我有一个对象,用于在启动画面关闭后在加载时添加工具提示。该对象看起来像这样:
layerNameMapping =
{
"samp_bldgs": {"title": "Sample_Bldgs", "index": 0, "tt": "Approximate center of buildings within BLE areas", "visible": false},
"buildings": { "title": "Buildings", "index": 1, "tt": "Approximate center of buildings within BLE areas", "visible": true},
"buildings_risk_chng": { "title": "Buildings Risk Change", "index": 2, "tt": "Color-coded change of building from effective flood hazard to BLE", "visible": false},
"contours": { "title": "Contours", "index": 3, "tt": "2ft contour lines", "visible": false},
"contours_diced": { "title": "Contours_Diced", "index": 4, "tt": "2ft contour lines", "visible": true},
"modeled_streamline": { "title": "Modeled Streamline", "index": 5, "tt": "Modeled stream centerlines for BLE studies", "visible": true},
"counties": { "title": "Counties", "index": 6, "tt": "County boundaries", "visible": true},
....
}
基本上,代码使用 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") 后,它在控制台中调试时中断并且永远不会移动到下一个项目。关于我在这里做错了什么的任何想法?