ASP Repeater生成的Javascript数组未更新

时间:2015-02-05 08:54:29

标签: javascript asp.net arrays google-maps repeater

我有一个转发器在客户端javascript中生成一个数组(用于谷歌地图标记)。它在第一次加载时工作正常,但是当我触发回发并将转发器与其他数据绑定时。转发器将初始数组值返回给我的变量。有什么办法出错吗?请帮忙

<script type="text/javascript">
  Var markers = [];
    function LoadMarker() {
    markers = [];
    var data =[
    <asp:Repeater ID="rptMarkers" runat="server">
    <ItemTemplate>
                {
                "title": '<%# Eval("DeviceName") %>',
                "lat": '<%# Eval("Latitude") %>',
                "lng": '<%# Eval("Longitude") %>',
                "Origlat": '<%# Eval("OrigLatitude") %>',
                "Origlng": '<%# Eval("OrigLongitude") %>',
                "description": '<%# Eval("Description") %>',
                "Status": '<%# Eval("Status") %>',
                "Active": '<%# Eval("Active") %>'
            }
    </ItemTemplate>
    <SeparatorTemplate>
        ,
    </SeparatorTemplate>
    </asp:Repeater>];
    markers = data;

    }

1 个答案:

答案 0 :(得分:0)

中继器对我不起作用,但我发现了另一种选择。从使用JavaScriptSerializer的序列化数据集后面的代码。然后将其解析为隐藏字段,以便客户端代码可以访问。

HTML

<asp:HiddenField ID="hfSortOrder" runat="server" />

JS

var markers = [];
markers = JSON.parse(document.get`enter code here`ElementById('<%= hfDummy.ClientID%>').value);
for (i = 0; i < markers.length; i++) {
var data = markers[i]
//Do your stuff etc: var info = data.column1
}

VB.NET

    Dim dsdata As New DataSet
    Dim dt As New DataTable()
    Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
    Dim rows As New List(Of Dictionary(Of String, Object))()
    Dim row As Dictionary(Of String, Object)

dsdata = ReadData()            

For Each dr As DataRow In dt.Rows
row = New Dictionary(Of String, Object)()
   For Each col As DataColumn In dt.Columns
      row.Add(col.ColumnName, dr(col))
   Next
rows.Add(row)
Next
hfDummy.Value = serializer.Serialize(rows)