在内部和外部的循环中变量相同的值
我有一个对象数组,将信息提供给生成“标记”的变量:
var markers = [
//testPOW
{ mesh: ["campDome","POW"],
color: iconRed,
location: {lat: 43.30985465943113, lng: 11.898409657895801},
visible: true,
id: "TestPOW",
category: "POW"
},
//testCamps
{ mesh: ["campDome","Camps"],
color: iconBlue,
location: {lat: 27.051081239338288, lng: 21.074973750899662},
visible: true,
id: "TestCamp",
category: "Camps"
},
//testInternedCivilians
{ mesh: ["campDome","InternedCivilians"],
color: iconYellow,
location: {lat: 47.866084023826794, lng: 2.61794289751219},
visible: true,
id: "TestInternedCivilians",
category: "InternedCivilians"
},
]
以下代码生成标记: //生成标记
for ( var i=0; i < markers.length; i++ ) {
var marker = this.addMarker( {
mesh : markers[i].mesh,
color: markers[i].color,
color2: 'white',
location : markers[i].location,
scale: 0.4,
offset: 0,
visible: markers[i].visible,
id: markers[i].id,
category: markers[i].category
} );
};
虽然不在生成标记的for循环内,但变量marker
是这样的:
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
这是最后一个要生成的
在循环内它是这样的:
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
我怎样才能得到它如果在 for 循环之外调用,marker
是否包含所有生成的对象?
I have an array of objects that feed info to a variable that generates "markers":
var markers = [
//testPOW
{ mesh: ["campDome","POW"],
color: iconRed,
location: {lat: 43.30985465943113, lng: 11.898409657895801},
visible: true,
id: "TestPOW",
category: "POW"
},
//testCamps
{ mesh: ["campDome","Camps"],
color: iconBlue,
location: {lat: 27.051081239338288, lng: 21.074973750899662},
visible: true,
id: "TestCamp",
category: "Camps"
},
//testInternedCivilians
{ mesh: ["campDome","InternedCivilians"],
color: iconYellow,
location: {lat: 47.866084023826794, lng: 2.61794289751219},
visible: true,
id: "TestInternedCivilians",
category: "InternedCivilians"
},
]
The following code generates the markers:
//Generate Markers
for ( var i=0; i < markers.length; i++ ) {
var marker = this.addMarker( {
mesh : markers[i].mesh,
color: markers[i].color,
color2: 'white',
location : markers[i].location,
scale: 0.4,
offset: 0,
visible: markers[i].visible,
id: markers[i].id,
category: markers[i].category
} );
};
While not inside the for loop that generates the markers, the variable marker
is this:
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
Which is just the last one to be generated
While inside the loop it's like this:
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
scripts.js:244
Earth.Marker {options: {…}, object3d: Vn, isMarker: true, earth: Earth, mesh: Array(2), …}
How can I get it marker
to include all of the generated objects if called outside the for loop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建数组有帮助吗?
还是,可能是一个对象?
Does creating an array help?
or, may be an object?