javascript - 错误 : SP. ClientContext().get_current throws uncaught typeError: undefined is not a function

标签 javascript sharepoint visual-studio-2013 sharepoint-2013

我正在关注这个 session 研讨会 http://video.ch9.ms/sessions/spc/2014/SPC261.mp4他们在哪里教你如何创建共享点应用程序

在某些时候我有这个脚本

$(document).ready(function () {

    //get context and then username
    context = new SP.ClientContext.get_Current();
    web = context.get_web();

    //get the tasks for the user
    getTaskCountForUser();


});

它只会计算任务列表中剩余的任务数。

我在应用程序部分 aspx 文件中包含下一个脚本

<%--<script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>--%>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script src="/_layouts/15/sp.js" type="text/javascript"></script>


<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.runtime.debug.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.debug.js" type="text/javascript"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.0/jquery-ui.min.js" type="text/javascript"></script>
<script src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-2.1.0.js" type="text/javascript"></script>
<script src="../Scripts/QuickTask.js" type="text/javascript"></script>

似乎一切正常。应用程序部分显示在 SharePoint Online 中,我可以将其包含在主页中,但脚本无法正常工作并在该行中抛出 Uncaught TypeError: undefined is not a function

context = new SP.ClientContext.get_Current();

我试过像这样封闭那个片段:

ExecuteOrDelayUntilScriptLoaded(function () {
   //my code above in here

}, "sp.js");

但在那种情况下,第一行会抛出相同的错误。

我错过了什么?我使用我的 MSDN 订阅 Vsual Studio 2013 中的 Sharepoint E3 在线帐户,在视频中,这个人无缝地浏览了它。

谢谢

最佳答案

您的代码中有一些拼写错误,调试 js 文件的链接(不是说这是不正确的,但为什么需要它们?)以及获取 ClientContext 对象时出错。

要修复脚本包含问题,请使用以下脚本标签代替您的:

<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.1.min.js" ></script>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js" ></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.0/jquery-ui.min.js" ></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-2.1.0.js" ></script>

但主要问题出在这一行:

context = new SP.ClientContext.get_Current();

在这种情况下,您不需要使用 new 关键字,您正在使用 getter 获取上下文对象。 应该是:

context = SP.ClientContext.get_current();

还要注意 get_current() 函数的大小写 - current 单词应该从小写字符开始。

关于javascript - 错误 : SP. ClientContext().get_current throws uncaught typeError: undefined is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23575047/

相关文章:

javascript - 使用 Lodash 在另一个字符串中使用 AND 搜索字符串数组

javascript - 如何在 Expressjs 或 Nodejs 中使用常规 Javascript 变量

javascript - Angular 服务中的 oop 类

.NET CMS 高流量网站

visual-studio-2013 - 在 VS2013 T4 脚手架模板中获取自定义属性

c++ - 使用 Visual 调试器释放内存非常慢

c++ - 使用无捕获 lambda 表达式作为条件运算符的第二个和第三个操作数时出现 MSVC 错误

javascript - 如何在ReactJS中做文档?

javascript - 使用 Javascript 显示共享点库项目

html - 如何使 Sharepoint 2010 Foundation 全局导航字体更大(自定义外观)