问题描述
我可以通过代码片段更好地解释我的情况
I can better explain my case by code snippet
var cascadiaFault = new google.maps.Polyline({
paths: [
new google.maps.LatLng(49.95, -128.1),
new google.maps.LatLng(46.26, -126.3),
new google.maps.LatLng(40.3, -125.4)
]
});
paths
属性的值应从外部变量pathsTemp
the value of paths
property should be assigned from external variable pathsTemp
var pathsTemp = [];
for (var i = 0; i < boxes.length; i++) {
var bounds = boxes[i];
// Perform search over this bounds
pathsTemp.push(bounds.getCenter());
}
var cascadiaFault = new google.maps.Polyline({
paths: pathsTemp;
});
它不起作用.
我尝试过的其他选项
paths = pathsTemp;
-不起作用paths: paths.push(pathsTmep)
-没有语法错误,但是到达此行时在运行时未捕获参考错误
paths = pathsTemp;
-- Not workingpaths: paths.push(pathsTmep)
-- No syntactic error but, uncaught reference error at runtime when this line is reached
PS:我没有javascript背景,但是我没有时间开始从头开始阅读语法和规则(但是,我可以理解大多数已编写的js代码)
PS: I don't have javascript background and unfortunately I don't have time to start reading the syntax and rules from scratch (However, I can understand most of the js code already written)
推荐答案
好,我明白了问题所在
- 正确的语法是
paths: pathsTemp
var pathsTemp = [];
for (var i = 0; i < boxes.length; i++) {
var bounds = boxes[i];
// Perform search over this bounds
pathsTemp.push(bounds.getCenter());
}
var cascadiaFault = new google.maps.Polyline({
paths: pathsTemp
});
- 上面的代码在语法上是正确的,但是问题在于它应该是
path
而不是paths
- The above code is syntactically correct, but the problem is it should be
path
instead ofpaths
尽管示例示例显示在https: //developers.google.com/maps/documentation/javascript/geometry#isLocationOnEdge
使用paths
,对我来说它与path
一起使用.可能是API文档中的错字
uses paths
, it works with path
for me. May be a typo in API documentation
如预期的那样,记录了文档错误
参考此stackoverflow讨论
with reference to this stackoverflow discussion
这篇关于javascript语法以从外部变量设置对象属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!