【发布时间】:2016-11-03 11:10:37
【问题描述】:
当我签入 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+/)}...
【问题讨论】:
-
在您发布的代码中的任何地方都看不到
t.replace。 -
@void 恐怕就是控制台所说的,不知道为什么,除了你在上面看到的以外,别无他法
-
控制台还应该指明一个行号,你应该能够与代码中的一行匹配,或者它可能在包含的脚本/库中
-
@trincot 它确实来自库,控制台说 leaflet.js:5 Uncaught TypeError: t.replace is not a function(...)
-
+= get_field('year') + ' '你想在这里做数学吗?如果没有,你在这里是 php,而不是 js 连接。所以使用点而不是加号。.= get_field('year') . ' '
标签: javascript php jquery json leaflet