【发布时间】:2016-01-10 12:50:57
【问题描述】:
在我的 Sharepoint 2010 Web 部件中,我有这个 Javascript:
function getListItemID(username, payeename, oList) {
var arrayListEnum = oList.getEnumerator();
...由此调用:
function upsertPostTravelListItemTravelerInfo1() {
var clientContext = SP.ClientContext.get_current();
var oList =
clientContext.get_web().get_lists().getByTitle('PostTravelFormFields');
this.website = clientContext.get_web();
currentUser = website.get_currentUser();
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
var travelersEmail = $('traveleremail').val();
/* If this is an update, the call to getListItemID() will return a val; otherwise (an insert), get from newly instantiated ListItem. */
listId = getListItemID(currentUser, travelersEmail, oList);
我从here 获得了此代码的基础。
但是得到了上面列出的错误(“Uncaught TypeError: oList.getEnumerator is not a function”);
一个回答说我需要添加这个:
<script type="text/javascript" src="/_layouts/15/sp.js" ></script>
...我将其从“15”更改为“14”,因为这是我们正在使用的文件夹/版本。
这不仅不起作用,而且无法识别。然后我找到了一条线索here,即添加这个:
$(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(CustomAction, "sp.js"); });
...但是在已经显示的错误之前只有一个错误,即“Uncaught ReferenceError: CustomAction is not defined”
那么,什么是独家新闻? getEnumerator() 或以其他方式检索我需要的 ID val 需要什么?
这是该方法的完整代码,以显示我要完成的工作以及如何完成:
function getListItemID(username, payeename, oList) {
var arrayListEnum = oList.getEnumerator();
while (arrayListEnum.moveNext()) {
var listItem = arrayListEnum.get_current();
if (listItem.get_item("ptli_formPreparedBy") === username &&
listItem.get_item("ptli_TravelersEmail") === payeename &&
listItem.get_item("ptli_formCompleted") == false) {
return listItem.get_id();
}
}
return '';
}
更新
当我尝试这个时(第一行和第三行是新的):
<SharePoint:ScriptLinkID="ScriptLink1" Name="SP.js" runat="server" OnDemand="false" LoadAfterUI="true" Localizable="false"></SharePoint:ScriptLink>
<script type="text/javascript">
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
...受到猫 here 的启发,我得到了,“System.Web.HttpParseException 未被用户代码处理 Message=服务器标签格式不正确。"
就我个人而言,我认为 Sharepoint 的格式不是很好。但那是(正确的)题外话(没有双关语)。
【问题讨论】:
-
oList返回的对象clientContext.get_web().get_lists().getByTitle()没有getEnumerator方法。关于调用getByTitle()的返回结果,SharePoint API 文档揭示了什么? -
我将在这里尝试更新的答案:stackoverflow.com/questions/33047426/… 它使用 getEnumerator(仍然)。我们会看看会发生什么......
标签: javascript jquery sharepoint-2010 web-parts