使用JavaScript查询SharePoint列表

时间:2014-05-03 23:24:13

标签: javascript sharepoint sharepoint-2013 sharepoint-list

我是一名新的SharePoint开发人员,我发现SharePoint有点困难。我一直在寻找一种使用JavaScript查询SharePoint 2013列表的方法,但我找不到明确的解决方案。

我要做的是验证我的"订阅列表中是否存在输入的电子邮件地址"。每次单击某个按钮时都会发生这种情况。验证将在我仍在尝试创建的模态视图中进行。

我在网上看到的一些帖子谈到sp.js文件,我不确定在哪里找到。另外,是SharePoint 2013的一些很好的教程。

3 个答案:

答案 0 :(得分:2)

包括SP.jsSP.Runtime.jsMicrosoft.Ajax.js。你的JavaScript看起来像这样(为方便起见使用jQuery ......):

$.ajax({
  url: "http://<DomainName>/<PathToWeb>/_api/web/lists/GetByTitle('<ListTitle>')/items",
  type: "GET",
  headers: {
    "accept": "application/json;odata=verbose",
  },
  success: function(data){
      $.each(data.d.results, function (key, value) {
        $("#ParentContainerId").append($("<pre></pre>")
                              .html(value.Title);
      });
  },
  error: function(error){
    alert(JSON.stringify(error));
  }
});

n.b。如果您需要除ID或标题之外的其他字段,则必须使用描述here所述的InternalName将它们包含在请求URL末尾的select语句中:

?$select=FileLeafRef

MS TechNet中有更多examples on how to retrieve and work with SharePoint ListItems using REST,MSDN中有更多documentation of the REST API

答案 1 :(得分:1)

使用javascript查询SharePoint数据有两种主要方法: 1)Javascript Client Object Model。在这种情况下,您需要添加位于布局虚拟文件夹中的SharePoint服务器上的SharePoint JavaScript库。 2)REST services

答案 2 :(得分:0)

我成功使用SPServices多年(虽然我目前没有做Sharepoint,而且我只使用了2007/2010)。

我相信你更具体地寻找GetListItems

相关问题