当我签入 console.log 并打破它时,以下内容在问题中产生错误
var map = L.map('map').setView([0, 0], 2);
<?php
$classesForCountries = [];
if (have_posts()) : while (have_posts()) : the_post();
$classesForCountries[ get_field('country') ] += get_field('year') + ' ';
endwhile; endif;
?>
// Now this should look something like {"Australia": "2006 2010 "}
var classNameMap = <?php echo JSON_encode($classesForCountries); ?>;
geojson = L.geoJson(statesData, {
style: function(feature) {
// Here is where we got the issue
var classes = classNameMap[feature.properties.sovereignt];
if (classes) {
return {className: classes};
}
},
}).addTo(map);
UPDATE
通过查看 console.log,它向我指出了库中的一行:
...t.replace(/^\s+|\s+$/g,"")},splitWords:function(t){return o.Util.trim(t).split(/\s+/)}...
“@Fred-ii- 哈哈,太棒了。非常感谢。将其放入答案中,我会接受。- rob.m”
根据OP的要求:
This += get_field('year') + ' '
您可能有 JS/C 背景,并认为+
PHP 中可以使用符号进行串联。 PHP 正在解释加号,认为您想做数学。
PHP 中连接的是点:
.= get_field('year') . ' '
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)