是什么导致这两个 .bindPopup 之间的错误?
What is causing the error between these two .bindPopup?
下面的弹出窗口可以正常显示“Neigh_Name”(名称,例如“Main”)和“2020 年总人口”(由数字“234273”等组成的字符串)。
layer.bindPopup(feature.properties.Neigh_Name+"<br>"+feature.properties["2020 Total Population"])
但是,当使用下面的..
layer.bindPopup(feature.properties["2020 Total Population"])
我收到错误:未捕获类型错误:无法在 'Node' 上执行 'appendChild':参数 1 不是 'Node' 类型。
谁能解释一下后端发生了什么,为什么这两行代码不同而后者最终失败了?我正在尝试了解为什么会发生某些事情以避免将来出现问题。
谢谢!
很可能 bindPopup
方法在将数字作为内容(您的第二行)传递时出现意外行为,而它很乐意接受字符串参数(如您的第一行)。
只需确保将您的参数转换为字符串,例如用 "" + feature.properties["2020 Total Population"]
或
`${feature.properties["2020 Total Population"]}`
下面的弹出窗口可以正常显示“Neigh_Name”(名称,例如“Main”)和“2020 年总人口”(由数字“234273”等组成的字符串)。
layer.bindPopup(feature.properties.Neigh_Name+"<br>"+feature.properties["2020 Total Population"])
但是,当使用下面的..
layer.bindPopup(feature.properties["2020 Total Population"])
我收到错误:未捕获类型错误:无法在 'Node' 上执行 'appendChild':参数 1 不是 'Node' 类型。
谁能解释一下后端发生了什么,为什么这两行代码不同而后者最终失败了?我正在尝试了解为什么会发生某些事情以避免将来出现问题。
谢谢!
很可能 bindPopup
方法在将数字作为内容(您的第二行)传递时出现意外行为,而它很乐意接受字符串参数(如您的第一行)。
只需确保将您的参数转换为字符串,例如用 "" + feature.properties["2020 Total Population"]
或
`${feature.properties["2020 Total Population"]}`