使用jquery创建动态数组
我需要一些关于 jquery 数组的帮助。
var queryArr;
$(markersArray).each(function(index) {
var _locationId = index;
var _locName = markersArray[index].name;
var _markerLat = markersArray[index].marker.getLatLng().lat();
var _markerLng = markersArray[index].marker.getLatLng().lng();
//I DO NOT KNOW THE SYNTAX BELOW HELP IN HERE PLEASE..
var locations = {
locationId:_locationId;
locationName:_locName,
lat:_markerLat,
lng:_markerLng }
queryStr = { "locations": locations} //??????????
});
queryArr.push(location); //???????
显然
我需要通过使用这样的方式来访问每个元素:
alert(queryArr[0].locations.locationId);
,我将使用 for 循环通过索引来访问每个数据。
任何人都可以给我示例语法吗?我发现了很多固定数组的示例,但没有找到动态内容。
I need some help regarding jquery arrays.
var queryArr;
$(markersArray).each(function(index) {
var _locationId = index;
var _locName = markersArray[index].name;
var _markerLat = markersArray[index].marker.getLatLng().lat();
var _markerLng = markersArray[index].marker.getLatLng().lng();
//I DO NOT KNOW THE SYNTAX BELOW HELP IN HERE PLEASE..
var locations = {
locationId:_locationId;
locationName:_locName,
lat:_markerLat,
lng:_markerLng }
queryStr = { "locations": locations} //??????????
});
queryArr.push(location); //???????
}
I need to reach each element by using sth like this:
alert(queryArr[0].locations.locationId);
Obviously I will be using a for loop to reach each data by an index.
Can anyone give me example syntax for this.. I have found plenty examples of fixed arrays but not dynamic content.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你们非常接近。带有推送的行需要移动到 .each() 循环内,并且您需要使用 queryStr 进行推送。确保没有任何其他语法错误,例如缺少分号。
queryArr.push(queryStr);
这是您的示例:
You're very close. The line with push needs to be moved inside the .each() loop and you need to use queryStr for the push. Make sure you don't have any other syntax errors like missing semicolons.
queryArr.push(queryStr);
Here's your example:
或者喜欢
or like