簡體   English   中英

為什么SP.js無法加載?

[英]Why is SP.js not loading?

我已經對此進行了徹底的研究,每個人都說我下面的代碼應該加載SP.js,但我無法加載它。

調試我得到:

NewForm.aspx, line 1667 character 5
SCRIPT5009: 'PeoplePicker' is undefined 

並且在視圖源下看不到SP.JS。

<SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" 
    Localizable="false" /> 
<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded(SetWebUserData(), "SP.js");

function SetWebUserData() {
    var pplPicker = new PeoplePicker();
    // Set the parent tag id of the people the picker.
    pplPicker.SetParentTagId('Main_x0020_Contact');
    pplPicker.SetLoggedInUser();
    };
</script>

任何幫助,不勝感激。

您正在使用ExecuteOrDelayUntilScriptLoaded錯誤。 您只應傳遞函數名稱,它應如下所示:

ExecuteOrDelayUntilScriptLoaded(SetWebUserData, "sp.js");

沒有()

我能夠解決此問題,並使用下面的代碼在當前用戶中填充了人員選擇器: http : //vbcity.com/blogs/skullcrusher/archive/2008/11/04/set-sharepoint-peoplepicker-field- mark-2.aspx

此代碼不需要SP.js

我一直無法正常加載sp.js,但是此解決方案解決了我的問題。

ExecuteOrDelayUntilScriptLoaded的第一個參數必須是一個函數 加載請求的腳本文件后,將調用此函數。

<SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" 
    Localizable="false" /> 
<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded(SetWebUserData, "SP.js");

function SetWebUserData() {
    var pplPicker = new PeoplePicker();
    // Set the parent tag id of the people the picker.
    pplPicker.SetParentTagId('Main_x0020_Contact');
    pplPicker.SetLoggedInUser();
    };
</script>

使用(),您可以調用一個函數。 這意味着,您的錯誤是將函數的結果作為參數傳遞, 不是函數本身。

更好理解的示例:

function helloFunction() {
    return 42;
}

var myHelloFunction = helloFunction; // Function is passed
var myHelloFunctionResult = helloFunction(); // Result of your function (42) is passed

我知道已經有點晚了,但是我認為這是您正在尋找的答案。

SP.SOD.executeFunc('sp.js', 'SP.ClientContext',function(){
  var pplPicker = new PeoplePicker();
  // Set the parent tag id of the people the picker.
  pplPicker.SetParentTagId('Main_x0020_Contact');
  pplPicker.SetLoggedInUser();
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM