当我检查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);
通过查看console.log,它指向库中的一行:
...t.replace(/^'s+|'s+$/g,"")},splitWords:function(t){return o.Util.trim(t).split(/'s+/)}...
"@Fred-ii- lol太棒了。非常感谢。把这句话写进答案里,我就接受。——rob.m"
根据OP的要求:
This += get_field('year') + ' '
你可能有JS/C背景,并且认为+
符号可以在PHP中用于连接。PHP把加号解释为你想做数学。
是PHP中连接的点:
.= get_field('year') . ' '