将两维数组从vb.net传递到javascript

时间:2014-07-29 19:06:58

标签: javascript asp.net vb.net

<script>
  var map,imageServiceLayer;
  var clr_default = [[164355, 71, 107, 161]];
  var clr_custom;
  require([
    "esri/map", "esri/layers/ArcGISImageServiceLayer", 
    "esri/layers/ImageServiceParameters", "dojo/parser", "dojo/domReady!"
  ], function(
    Map, ArcGISImageServiceLayer, 
    ImageServiceParameters, parser
  ) {
    parser.parse();
    esri.config.defaults.io.corsEnabledServers.push("http://mapsdev.lib.purdue.edu:6080");

    map = new Map("map", {
      basemap: "topo",
      center: [-100, 33],
      zoom: 5
    });

    var rasterFunction = new esri.layers.RasterFunction();
    var arguments = {};
    arguments.Colormap=clr_default;
    rasterFunction.arguments = arguments;
    rasterFunction.functionName = "Colormap";
    var params = new ImageServiceParameters();
    //params.renderingRule=rasterFunction;
    imageServiceLayer = new ArcGISImageServiceLayer("http://mapsdev.lib.purdue.edu:6080/arcgis/rest/services/ISEE/ISEE2Dev_IN_DBO_gSSURGO_IN_10m/ImageServer", {
      imageServiceParameters: params,
      opacity: 0.75
    });
    map.addLayer(imageServiceLayer);
  });
  function changeColor(val){
    var rasterFunction = new esri.layers.RasterFunction();
    var arguments = {};     
  if (val == "Default")
  imageServiceLayer.setRenderingRule(null);
  else if (val == "Default1")
  {
    arguments.Colormap=clr_default;
    rasterFunction.arguments = arguments;
    rasterFunction.functionName = "Colormap";
    imageServiceLayer.setRenderingRule(rasterFunction);
  }
  else if (val == "Custom")
  {
    arguments.Colormap=clr_custom;
    rasterFunction.arguments = arguments;
    rasterFunction.functionName = "Colormap";
    imageServiceLayer.setRenderingRule(rasterFunction);
  }
  }
</script>

Dim sb As New StringBuilder
sb.Append("var clr_custom=new Array(" & (i + 1) & ");")
    For j As Integer = 0 To i
        sb.Append("clr_custom[" & j & "]=new Array(4);")
        For k As Integer = 0 To 3
            sb.Append("clr_custom[" & j & "][" & k & "]=" & color(j, k) & ";")
        Next
    Next

这是我的java脚本。在第四行,变量clr_custom是二维数组,需要从服务器数据库中获取值,我尝试这样做,如上面vb.net所示。一种方法是使用registerstartupscript()为整体javascript,但是这很难编辑java脚本。有什么简单的定义vb.net中的变量值并在javascript中使用相同的变量

1 个答案:

答案 0 :(得分:0)

看起来你只想在你的javascript中间<%= sb.ToString() %>