代码在EDIT视图中工作,而不是SAVED页面

时间:2017-01-12 18:08:47

标签: dictionary sharepoint

我的使命:从列表中创建一个地图,例如:

Map

编辑SharePoint页面时(编辑模式/视图),地图在控制台中不会抛出任何错误。但是当我去查看最终保存页面的地图时,我在控制台中收到了这个错误:

Event Page.aspx:668 Uncaught TypeError: Cannot read property 'get_current' of undefined at retrieveListItems (Event Page.aspx:668) at Event Page.aspx:789

此错误指向此行:

var clientContext = new SP.ClientContext.get_current();

似乎PAGE缺少一些在我编辑模式时添加的资源。

此代码从列表中获取信息以传递给地图脚本。

function retrieveListItems() {
    var listName = "North East Events";
    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle(listName);
    this.website = clientContext.get_web();

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' +
        '<Value Type=\'Number\'>1</Value></Geq></Where></Query><RowLimit>50</RowLimit></View>');
    collListItem = oList.getItems(camlQuery);

    clientContext.load(this.website);
    clientContext.load(this.collListItem);

    clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));

}

function onQuerySucceeded(sender, args) {
    var geocoder;
    var map;
    var bounds = new google.maps.LatLngBounds();
    var listItemInfo = '';
    var locations = [];
    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();

        var eventName = oListItem.get_item('Title');
        var eventAddress = oListItem.get_item('WorkAddress');
        var eventURL = website.get_url() + '/' + 'Lists/North East Reports/DispForm.aspx?ID=' + oListItem.get_id();

        var newLocations = [eventName, eventAddress, eventURL];
        locations.push(newLocations);

    }

    google.maps.event.addDomListener(window, "load", initialize);

    function initialize() {
        map = new google.maps.Map(
            document.getElementById("map_canvas"), {
                center: new google.maps.LatLng(37.4419, -122.1419),
                zoom: 13,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            });
        geocoder = new google.maps.Geocoder();

        for (i = 0; i < locations.length; i++) {

            geocodeAddress(locations, i);
        }
    }


    function geocodeAddress(locations, i) {
        var title = locations[i][0];
        var address = locations[i][1];
        var url = locations[i][2];
        geocoder.geocode({
                'address': locations[i][1]
            },

            function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    var marker = new google.maps.Marker({
                        icon: 'http://maps.google.com/mapfiles/ms/icons/blue.png',
                        map: map,
                        position: results[0].geometry.location,
                        title: title,
                        animation: google.maps.Animation.DROP,
                        address: address,
                        url: url
                    })
                    infoWindow(marker, map, title, address, url);
                    bounds.extend(marker.getPosition());
                    map.fitBounds(bounds);
                } else {
                    alert("geocode of " + address + " failed:" + status);
                }
            });
    }

    function infoWindow(marker, map, title, address, url) {
        google.maps.event.addListener(marker, 'click', function() {
            var html = "<div><h3>" + title + "</h3><p>" + address + "<br></div><a href='" + url + "'>View location</a></p></div>";
            iw = new google.maps.InfoWindow({
                content: html,
                maxWidth: 350
            });
            iw.open(map, marker);
        });
    }

    function createMarker(results) {
        var marker = new google.maps.Marker({
            icon: 'http://maps.google.com/mapfiles/ms/icons/blue.png',
            map: map,
            position: results[0].geometry.location,
            title: title,
            animation: google.maps.Animation.DROP,
            address: address,
            url: url
        })
        bounds.extend(marker.getPosition());
        map.fitBounds(bounds);
        infoWindow(marker, map, title, address, url);
        return marker;
    }




}




function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
retrieveListItems();

enter image description here

0 个答案:

没有答案