Dictionary 代码在“编辑”视图中工作,而不是保存页面
我的任务:从以下列表创建地图: 编辑SharePoint页面(编辑模式/视图)时,地图不会在控制台中抛出错误。但当我去查看地图上最后保存的页面时,我在控制台中遇到了以下错误:Dictionary 代码在“编辑”视图中工作,而不是保存页面,dictionary,sharepoint,Dictionary,Sharepoint,我的任务:从以下列表创建地图: 编辑SharePoint页面(编辑模式/视图)时,地图不会在控制台中抛出错误。但当我去查看地图上最后保存的页面时,我在控制台中遇到了以下错误: Event Page.aspx:668未捕获类型错误:无法读取未定义的属性“get\u current” 在retrieveListItems(事件页aspx:668) 在事件页面。aspx:789 此错误指向此行: var clientContext = new SP.ClientContext.get_current
Event Page.aspx:668未捕获类型错误:无法读取未定义的属性“get\u current”
在retrieveListItems(事件页aspx:668)
在事件页面。aspx:789
此错误指向此行:
var clientContext = new SP.ClientContext.get_current();
当我处于编辑模式时,页面似乎缺少一些添加的资源
此代码从列表中获取要传递给映射脚本的信息
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();
函数retrieveListItems(){
var listName=“东北事件”;
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(“”+
'150');
collListItem=oList.getItems(camlQuery);
clientContext.load(this.website);
load(this.collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this,onQuerySucceed),Function.createDelegate(this,onQueryFailed));
}
函数onquerysucceed(发送方,参数){
var地理编码器;
var映射;
var bounds=new google.maps.LatLngBounds();
var listItemInfo='';
var位置=[];
var listItemEnumerator=collListItem.getEnumerator();
while(listItemEnumerator.moveNext()){
var oListItem=listItemEnumerator.get_current();
var eventName=oListItem.get_项('Title');
var eventAddress=oListItem.get_项(“工作地址”);
var eventURL=website.get_url()+'/'+'列表/东北报告/DispForm.aspx?ID='+oListItem.get_ID();
var newLocations=[eventName,eventAddress,eventURL];
地点。推送(新地点);
}
google.maps.event.addDomListener(窗口“加载”,初始化);
函数初始化(){
map=新建google.maps.map(
document.getElementById(“地图画布”){
中心:新google.maps.LatLng(37.4419,-122.1419),
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
geocoder=新的google.maps.geocoder();
对于(i=0;i”;
iw=新建google.maps.InfoWindow({
内容:html,
最大宽度:350
});
iw.打开(地图、标记);
});
}
函数createMarker(结果){
var marker=new google.maps.marker({
图标:'http://maps.google.com/mapfiles/ms/icons/blue.png',
地图:地图,
位置:结果[0]。geometry.location,
标题:标题,,
动画:google.maps.animation.DROP,
地址:地址:,
url:url
})
extend(marker.getPosition());
映射边界(bounds);
信息窗口(标记、地图、标题、地址、url);
返回标记;
}
}
函数onQueryFailed(发送方,参数){
警报('请求失败。'+args.get_message()+'\n'+args.get_stackTrace());
}
retrieveListItems();
使用
clientContext.load(this.collListItem)代码>而不是clientContext.load(collListItem)代码>@Mike不工作:(,任何主体?好的,我重新组织了代码并移动了一些内容,使其仅在编辑模式下工作。单击“保存代码”后,代码停止工作,发布更多信息加载SP.js或任何其他特定于SP的js文件时登录控制台是否有错误?您是否尝试过清除缓存和刷新页面?您需要等待sp.js加载。将以下内容放在末尾,而不是retrieveListItems()
:$(document).ready(function(){executeOrderLayuntilScriptLoaded(retrieveListItems,“sp.js”);};
);