Javascript OneacheFeatures不显示内容,但显示[对象]
我在以下geojson中有一个链接,希望显示每个功能的人员详细信息Javascript OneacheFeatures不显示内容,但显示[对象],javascript,leaflet,geodjango,Javascript,Leaflet,Geodjango,我在以下geojson中有一个链接,希望显示每个功能的人员详细信息 <body> <h1>Ownership</h1> <script type="text/javascript"> function our_Layers (map, options){ var datasets = new L.GeoJSON.AJAX("{% url 'owner' %}",{
<body>
<h1>Ownership</h1>
<script type="text/javascript">
function our_Layers (map, options){
var datasets = new L.GeoJSON.AJAX("{% url 'owner' %}",{
onEachFeature: function(feature, layer){
layer.bindTooltip(feature.properties.Registrations.persons.toString(),
{permanent:true, direction: 'right'});
}
});
datasets.addTo(map);
}
</script>
{% leaflet_map "Owners" callback="window.our_Layers" %}
</body>
下面是我的Geojson输出的属性部分
"properties": {"lr": "26697/751", "Registrations": {"Tenure_type": "leasehold", "persons": [{"PersonID": 7475, "name1st": "benard", "name2st": "gramps", "telephone": "02857215"}, {"PersonID": 7512, "name1st": "Jackie", "name2st": "morgan", "telephone": "0248571264"}]}}}
这是我的代码
<body>
<h1>Ownership</h1>
<script type="text/javascript">
function our_Layers (map, options){
var datasets = new L.GeoJSON.AJAX("{% url 'owner' %}",{
onEachFeature: function(feature, layer){
layer.bindTooltip(feature.properties.Registrations.persons.toString(),
{permanent:true, direction: 'right'});
}
});
datasets.addTo(map);
}
</script>
{% leaflet_map "Owners" callback="window.our_Layers" %}
</body>
所有权
功能我们的_层(地图、选项){
var datasets=new L.GeoJSON.AJAX(“{%url'所有者'%}”,{
onEachFeature:函数(特性,层){
layer.bindTooltip(feature.properties.Registrations.persons.toString(),
{永久:正确,方向:'正确'});
}
});
数据集。添加到(地图);
}
{%mopale\u map“owner”callback=“window.our\u Layers”%}
我认为您需要使用JSON.stringify()函数来解析您的对象:
layer.bindTooltip(JSON.stringify(feature.properties.Registrations.persons),
{permanent:true, direction: 'right'});
为了查看JSON.stringify()和.toString方法之间的差异,我创建了以下代码段:
var个人=[
{“PersonID”:7475,“name1st”:“benard”,“name2st”:“gramps”,“电话”:“02857215”},
{“PersonID”:7512,“name1st”:“Jackie”,“name2st”:“morgan”,“电话”:“0248571264”}
];
log(JSON.stringify(persons));
console.log(persons.toString())代码>是feature.properties.Registrations.persons对象吗?persons属性包含在上面给出的我的geojson输出的[]中。有没有办法在弹出窗口中显示它们。谢谢,它成功了。有没有一种方法可以格式化JSON.stringify输出。like删除一些字符或颜色。您可以像编辑普通字符串一样编辑它,因此使用.replace()方法编辑或删除一些字符。e、 如果你想删除“Hello world”中的所有“l”字符,只需使用“Hello world”。替换('l','')。这会给你一个“好词”。有关更多信息,请参阅。