【发布时间】:2019-10-09 17:13:54
【问题描述】:
我正在尝试在用户单击按钮时创建 SharePoint 列表项。 我不知道如何解决我遇到的错误。不过,代码似乎仍能按预期工作。
HTML 源代码:
<button type="button" class="btn btn-info" id="getPollval">Submit</button>'
脚本 - 从单选按钮中获取值:
var pName = '[name="Poll' + pollId + '"]:checked';
var pId = 'Poll' + pollId;
document.getElementById("getPollval").onclick = function() {
var pollValue = document.querySelector(pName);
createListItem(pollValue.value, pId , pollTitle);
}
脚本 - 在 SharePoint 上创建列表项:
var siteUrl = '/sites/MyList';
function createListItem(pollValue, pId, pollTitle) {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('PollCustomResponses');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', pollTitle);
oListItem.set_item('Response', pollValue);
oListItem.set_item('PollID', pId);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
alert('Item created: ' + oListItem.get_id());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
当我单击submit 按钮时,它会按预期创建一个新的列表项。但是,我在 DevTools 中收到以下错误消息:
未捕获的类型错误:无法读取未定义的属性“应用”
错误是检查时突出显示clientContext.executeQueryAsync 行。
【问题讨论】:
标签: javascript sharepoint-online