在JavaScript循环中放置服务器端变量 [英] Place Server side Variable in javascript loop
问题描述
我有一个服务器端变量通过以下代码:
I have a Server side variable by the following code
Dim mgps As New Text.StringBuilder
Public ReadOnly Property GPS() As String
Get
Return mgps.ToString
End Get
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim con As New OleDbConnection
con = New OleDbConnection("Data Source=sml; User ID=sml; Password=sml; provider=OraOLEDB.Oracle")
con.Open()
Dim cmd As OleDbCommand = New OleDbCommand("Select STA_NAME, GPS_ONE from GPS", con)
Dim ds As New DataSet
Dim I As Long
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, "GPS")
mgps.AppendLine("[")
For I = 0 To ds.Tables("GPS").Rows.Count - 1
mgps.AppendLine(ds.Tables("GPS").Rows(I).Item("GPS_ONE") & ",")
Next I
mgps.AppendLine("];")
End Sub
GPS
现在我试图在客户端JS Array中访问它
JS Array低于
Now I am trying to access it in client side JS Array JS Array is below
var store_locations = new Array();
store_locations = [
new google.maps.LatLng(31.204549793299,72.264183974237),
new google.maps.LatLng(31.23004996385,72.282225091978),
new google.maps.LatLng(31.148218,72.224542),
new google.maps.LatLng(31.2330555556,72.3330555556)
];
现在我想在store_locations中使用GPS变量值而不是custome值。
Now I want to use GPS varible values instead of custome values in store_locations.
如何做任何人请帮助我。
How can it be done anyone please help me.
这是我想要访问数组值的循环。
Here is my loop where I want to access the array values.
for(i=0; i<store_locations .length-1; i++)
{
var image = 'ico/no.png';
markers[i] = new google.maps.Marker(
{
position: store_locations [i],
map: map,
draggable:true,
icon:image,
title: (i+1) + GPS
});
}
我可以像下面那样访问GPS变量
I have access the GPS variable as below
var GPS = <%=GPS %>
并用GPS替换store_locations,但我的地图变为空。
and replace the store_locations with GPS but my map become empty.
请告诉我我到底错过了什么?
Please tell me what exactly i am missing to do this?
推荐答案
您可以创建一个公共属性返回代码中的GPS值。创建字符串
或 StringBuilder
对象并定义公共属性。
You may create a public property that returns GPS value in code-begind. Create a String
or StringBuilder
object and define public property.
Dim mgps As new Text.StringBuilder
Public ReadOnly Property GPS As String
Get
Return mgps.ToString
End Get
End Property
使用mgps(stringbuilder)对象从数据库结果中添加数据。 / p>
Use mgps (stringbuilder) object to add data from database result.
mgps.AppendLine("[")
For I = 0 To ds.Tables("GPS").Rows.Count - 1
mgps.AppendLine(ds.Tables("GPS").Rows(I).Item("GPS_ONE") & ",")
Next I
mgps.AppendLine("];")
现在,您可以在JavaScript中使用GPS:
Now you can use GPS in JavaScript:
var GPS = <%=GPS %>
这篇关于在JavaScript循环中放置服务器端变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!