控制器和Cshtml上的无限循环

时间:2013-12-19 05:30:03

标签: javascript jquery asp.net-mvc asp.net-mvc-3 razor

我目前正在开发谷歌地图API,但它对我来说是新的,所以我读了一些页面并开始工作,直到我遇到这种错误/故障,其中值保持循环直到页面崩溃。 。

有人可以帮助我或指出我代码中的问题: 我没有错误

这是我的Cshtml中的代码:

<script type="text/javascript">
    var geocoder, infoBubble;
    var map;
    //var mgr;

    function initialize() {
        var minZoomLevel = 4;
        var zooms = 7;
        geocoder = new google.maps.Geocoder();

        map = new google.maps.Map(document.getElementById('map'), {
            zoom: minZoomLevel,
            center: new google.maps.LatLng(38.50, -90.50),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        });

        // Bounds for North America
        var strictBounds = new google.maps.LatLngBounds(
     new google.maps.LatLng(15.70, -160.50),
     new google.maps.LatLng(68.85, -55.90)
   );

        // Listen for the dragend event
        google.maps.event.addListener(map, 'dragend', function () {
            if (strictBounds.contains(map.getCenter())) return;

            // We're out of bounds - Move the map back within the bounds

            var c = map.getCenter(),
         x = c.lng(),
         y = c.lat(),
         maxX = strictBounds.getNorthEast().lng(),
         maxY = strictBounds.getNorthEast().lat(),
         minX = strictBounds.getSouthWest().lng(),
         minY = strictBounds.getSouthWest().lat();

            if (x < minX) x = minX;
            if (x > maxX) x = maxX;
            if (y < minY) y = minY;
            if (y > maxY) y = maxY;

            map.setCenter(new google.maps.LatLng(y, x));
        });


        // Limit the zoom level
        google.maps.event.addListener(map, 'zoom_changed', function () {
            if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
        });

        codeAddress();

    }
    var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
    function codeAddress() {
        infoBubble = new InfoBubble({
            map: map,
            shadowStyle: 0,
            padding: 10,
            borderRadius: 10,
            arrowSize: 15,
            maxWidth: 300,
            borderWidth: 1,
            borderColor: '#ccc',
            arrowPosition: 50,
            arrowStyle: 0
        });
        $.getJSON('/Dashboard/LoadWorkerList', function (address) {
            $.each(address, function () {
                var currVal = this["AddressLine1"];
                var Name = this["Name"];
                var Gender = this["Gender"];
                var Bdate = this["Birthdate"];
                var ID = this["Worker_ID"];
                geocoder.geocode({ 'address': currVal }, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        var marker = new google.maps.Marker({
                            map: map,
                            icon: iconBase + 'man.png',
                            position: results[0].geometry.location,
                            title: currVal
                        })

                        var link = $('<a href="#">'+currVal+'</a>')
                         .data('location', results[0].geometry.location);
                        $('#places').append($('<li>').append(link));
                        link.on('click', function (event) {
                            event.preventDefault();
                            google.maps.event.trigger(address[0], "click");
                            infoBubble.removeTab(0);
                            infoBubble.addTab(Name, "Name: " + Name + "<br> Address: " + currVal + "<br> Gender: " + Gender + "<br> Birthdate: " + Bdate + "<br><br>" + '<center><a href="/Worker/WorkerDetails?workerId=' + ID + '">View Profile</a></center>');
                            infoBubble.open(map, marker);
                        }
);

                        google.maps.event.addListener(map, 'idle', function () {
                            $('#places li a').css('display', function () {
                                return (map.getBounds().contains($(this).data('location')))
                      ? ''
                      : 'none';
                            });
                        });
    </script>

这是我控制器中的代码:

public JsonResult LoadWorkerList()
        {
            var workerList = new List<Worker_Address>();

            // check if search string has value
            // retrieve list of workers filtered by search criteria
            var list = (from a in db.Worker_Address
                        join b in db.Workers
                            on a.WorkerID equals b.ID
                        where a.LogicalDelete == false
                              && b.LogicalDelete == false
                        select new
                                   {
                                       b.ID,
                                       b.LastName,
                                       b.FirstName,
                                       b.MiddleName,
                                       b.Gender_LookID,
                                       b.BirthDate,
                                       a.WorkerID,
                                       a.Address_Line1,
                                       a.Address_Line2,
                                       a.City,
                                       a.State_LookID,
                                       a.ZipCode,
                                       a.LogicalDelete,
                                   }).ToList();





            List<WorkerAddressInfo> wlist = new List<WorkerAddressInfo>();
            foreach (var row in list)
            {
                WorkerAddressInfo ci = new WorkerAddressInfo
                                           {
                                               ID = row.ID,
                                               Worker_ID = row.WorkerID,
                                               AddressLine1 =
                                                   row.Address_Line1 + " " + row.Address_Line2 + " " + row.City + " " +
                                                   GetLookupDisplayValById(row.State_LookID),
                                               Name = row.FirstName + " " + row.MiddleName + " " + row.LastName,
                                               Birthdate = row.BirthDate.ToString("MM/dd/yy"),
                                               Gender = GetLookupDisplayValById(row.Gender_LookID),
                                               LogicalDelete = row.LogicalDelete

                                           };
                wlist.Add(ci);
            }


            return Json(wlist.ToList().OrderBy(p => p.AddressLine1), JsonRequestBehavior.AllowGet);
        }

0 个答案:

没有答案