将对象项传递给javascript函数 [英] pass object items to a javascript function

查看:47
本文介绍了将对象项传递给javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个方法,它返回一个客户列表及其地理坐标。由customerName,纬度和经度组成。我的问题是如何将该对象传递给javascript函数。

首先,我很难对我的javascript中的值进行编码,如图所示



&

Hello all,

I have a method which returns a list of customers with their geographical coordinates.The consists of customerName,latitude and longitude.My problem is on how to pass that object to a javascript function.
At first,i am hard coding the values in my javascript as shown

&

<pre lang="Javascript"><pre lang="Javascript">

lt; script type =text / javascript>

var locations = [

['Customer 1',15.45534486191928,18.72465389941408,4],

['Customer 2',15.443555941025974,18.750574767334,5],< br $>




];





var map = new google.maps.Map(document.getElementById('map'),{

zoom:10,

center:new google.maps.LatLng(1.2920659, 36.82194619999996),

mapTypeId:google.maps.MapTypeId.ROADMAP

});



var infowindow = new google.maps.InfoWindow();



var marker,i;



for(i = 0;我< locations.length; i ++){

marker = new google.maps.Marker({

position:new google.maps.LatLng(locations [i] [1],locations [i] [2]),

地图:地图

});



google.maps.event.addListener (标记,'点击',(功能(标记,i){

返回功能(){

infowindow.setContent(locations [i] [0]);

infowindow.open(地图,标记);

}

})(标记,i));

}

< / script>



下面是一个对象

列表< customers> customer = getAllCustomers();



我需要选择对象客户并将其传递给javascript函数而无需对其进行硬编码。如何解决这个问题? Tx

lt;script type="text/javascript">
var locations = [
['Customer 1', 15.45534486191928, 18.72465389941408, 4],
['Customer 2', 15.443555941025974, 18.750574767334, 5],


];


var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(1.2920659, 36.82194619999996),
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var infowindow = new google.maps.InfoWindow();

var marker, i;

for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});

google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>

Below is an object
List<customers> customer=getAllCustomers();

I need to pick the object customer and pass it to the javascript function without hardcoding it.How can i solve this?Tx

推荐答案

这篇关于将对象项传递给javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆