无法访问父 SharePoint URL.未捕获的类型错误: 无法读取未定义的属性“get_web”
Cannot get to parent Sharepoint URL. Uncaught TypeError: Cannot read property 'get_web' of undefined
我正在尝试将值保存到共享点列表。我可以使用"SP.ClientContext.get_current((;"没有问题。但是,我想仅使用 URL 将其保存到部分站点上的同名列表中。获取以下错误:未捕获的类型错误:无法读取未定义的属性"get_web">
var siteUrl;
siteUrl = '/sites/Mysite/';
var clientContext = SP.ClientContext(siteUrl);/*.get_current();*/
var oList = clientContext.get_web().get_lists().getByTitle('QuizResults');
var itemCreateInfo = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(itemCreateInfo);
var vURL = (document.URL);
var vScore = 'score';
var vDate = new Date();
oListItem.set_item('Title', vURL);
oListItem.set_item('Score', vScore);
oListItem.set_item('Date', vDate);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this,onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
function onQuerySucceeded()
{
('Item created: ' + oListItem.get_id());
}
function onQueryFailed(args)
{
('Request failed. ' + args.get_message() + ''n' + args.get_stackTrace());
}
//end of section for adding score to list
如果使用SP.ClientContext(siteUrl)
函数(构造函数(而不是调用get_current()
,则应将其与new
关键字一起使用以实例化新上下文。
var clientContext = new SP.ClientContext.(siteUrl);
get_current()
函数返回适用于当前页面/站点的上下文。当您传入 URL 时,您需要实际创建一个新 URL。
谢谢 John-M,但我实际上通过执行以下操作解决了这个问题:
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_site().get_rootWeb().get_lists().getByTitle('QuizResults');
添加的部分是".get_site((.get_rootWeb((">
使用站点 URL 为根站点打开新站点
string rootSiteUrl = SPContext.Current.Web.Site.Url;
using (SPSite site = new SPSite(rootSiteUrl ))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.GetList("QuizResults");
//Add item here
}
}
相关文章:
- TypeError:无法读取属性'推'未定义的JavaScript
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 未捕获的类型错误:无法读取属性'删除'的未定义
- AngularJS指令出错-无法读取属性'编译'的未定义
- 看到“;未捕获的类型错误:无法读取属性'weight'未定义的“;尽管按照字面上的指示
- angularjs无法读取未定义的属性then
- 无法读取属性'材料'未定义的Three.js
- 得到"TypeError:无法读取属性'filename'未定义的“;调用“npm start
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- JavaScript承诺-无法读取属性'那么'的未定义
- 未捕获的类型错误:无法读取属性'中止'的未定义
- 角度推入数组给出:TypeError:无法读取属性'推'的未定义
- Javascript未捕获类型错误:无法读取属性'0'的未定义
- jQuery控制台错误:无法读取属性'top'的未定义
- TypeError:无法读取属性'findAll'的未定义
- 无法读取属性'errcap'未定义的jqgrid
- 无法读取未定义的属性“rid”
- 未捕获的类型错误: 无法读取未定义的属性“图像”
- 可以't读取'getHTML'未定义的Liferay CK Editor内容
- 在node.js中未定义读取属性错误