如何使用razor语法将模型值推送到二维javascript数组? [英] How do I push model values into 2 dimensional javascript array with razor syntax?

查看:106
本文介绍了如何使用razor语法将模型值推送到二维javascript数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用模型数据将位置添加到谷歌地图标记中,但是地图没有加载并提示我杀死页面,就好像我将40个静态位置放到标记中,它加载得很好,我怎么做下面的模型数据加载标记值是我的代码

I'm trying to add locations into google map marker with model data,but map doesn't load and prompt me to kill page, where as if i put 40 static locations to a marker, it loads well, how do i load marker values with model data below is my code

<pre> var map = new google.maps.Map(document.getElementById('googleMap'), {
        zoom: 5,
        center: new google.maps.LatLng(40.4931300000, -79.8631100000),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

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

    var marker, i;
    var locations = [];
   
    @for(int i = 0; i < Model.pallet.Lattitudes.Count; i++)
    {
        if (Model.pallet.Lattitudes[i] != null) {
        @:locations.push(new google.maps.LatLng('@Model.pallet.Lattitudes[i]', '@Model.pallet.Longitudes[i]'));
    }
    }
    for (i = 0; i < locations.length; i++) {
        marker = new google.maps.Marker({
            position: locations[i],
        });
        marker.setMap(map);
        google.maps.event.addListener(marker, 'click', (function (marker, i) {
            return function () {
                infowindow.setContent(locations[i][0]);
                infowindow.open(map, marker);
            }
        })(marker, i));
    }





我的尝试:



i尝试将40个硬编码位置值放入数组并加载良好,但是模型数据不起作用



What I have tried:

i tried putting 40 hard cocded location values into array and loads well ,but with model data it doesn't work

推荐答案

我们不知道什么在你的模型中,所以我们无法找到;只有你可以。



尝试查看页面的源代码,看看你的视图生成的JavaScript代码是什么。如果出现问题,请找出它的来源 - 如有必要,您可以使用调试器。
We don't know what's in your model, so we can't find out; only you can.

Try to take a look at the source code of your page, and look what the JavaScript code is that your view generated. If something is wrong with that, find out where this comes from - you can use your debugger if necessary.


这篇关于如何使用razor语法将模型值推送到二维javascript数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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