我正在尝试将动态创建的对象映射到这样的数组
params.junctionBarriers = dojo.toJson(junctionBarriers);
// printing the object in the console (Please look at attached image)
console.log(params.junctionBarriers);
var value = [];
var data = params.junctionBarriers.map(function (s) {
value.push(webMercatorUtils.xyToLngLat(s.x, s.y, true));
return s;
})
但是我收到了这个错误
params.junctionBarriers.map is not a function
正如您从图像中看到的那样,params.junctionBarriers
是动态加载的,但 .map()
无效。这是为什么,我该如何解决?
最佳答案
Look at the documentation for dojo.toJson
该方法将对象转换为 JSON 格式的字符串。
字符串没有方法映射。
那你为什么不简单地做 junctionBarriers.map
?鉴于您已经在该变量中拥有对象数组(这不是 params.junctionBarriers)
关于javascript - .map() 不是函数映射动态创建的对象时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47662184/