链接到共享点列表

时间:2018-06-20 14:12:03

标签: javascript html sharepoint hyperlink

我试图编写一段链接到共享点列表(UtilitiesContracts)并引入某些列(客户端)的代码。但是,当我运行代码时,它似乎没有链接数据。有人可以发现我的代码有什么问题吗?

这是加载代码1

时出现的内容

<script src="https://www.datatables.net/release-datatables/extensions/ColReorder/js/dataTables.colReorder.js"></script>
<!--SPServices Javascript-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
<!--SpServices JavaScript get items from list 'files'-->
<script language="javascript" type="text/javascript">
  $(document).ready(function() {
    var myQuery =
      "<Query>" +
      "<OrderBy>" +
      "<FieldRef Name='Client' />" +
      "</OrderBy>" +
      "</Query>";
    $().SPServices({
      webURL: "https://ext.kier.co.uk/teams/Utilities/",
      operation: "GetListItems",
      async: false,
      listName: "UtilitiesContracts",
      CAMLQuery: myQuery,
      CAMLRowLimit: 100,
      completefunc: function(xData, Status) {
        var liHtml = "<tbody>";
        $(xData.responseXML).SPFilterNode("z:row").each(function() {
          liHtml = liHtml + " <tr><td>" + $(this).attr("ows_Client") + "</td><td>" + $(this).attr("ows_Title1") + "</td><td>" + $(this).attr("ows_Title2") + "</td><td>" + $(this).attr("ows_Title3")+ "</td></tr>";
        });
        liHtml += "</tbody>";
        $("#example").append(liHtml);
      }
    });
    $('#example').DataTable({
      "dom": 'Rlfrtip'
    });
  });

</script>
<table id="example" class="display" cellspacing="0" width="100%">
  <thead>
    <tr>
      <th>Client</th>
      <th>Title1</th>
      <th>Title2</th>
      <th>Title3</th>
    </tr>
  </thead>
</table>

1 个答案:

答案 0 :(得分:0)

您无法在本地计算机HTML文件中运行代码。

您需要将以下代码添加到SharePoint页面中,以使其正常工作。

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">    
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/css/dataTables.jqueryui.min.css">
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>    
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> 
<script src="https://www.datatables.net/release-datatables/extensions/ColReorder/js/dataTables.colReorder.js"></script>
<!--SPServices Javascript-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
<!--SpServices JavaScript get items from list 'files'-->
<script language="javascript" type="text/javascript">
  $(document).ready(function() {
    var myQuery =
      "<Query>" +
      "<OrderBy>" +
      "<FieldRef Name='Client' />" +
      "</OrderBy>" +
      "</Query>";
    $().SPServices({
      webURL: "http://sp2013/sites/team",
      operation: "GetListItems",
      async: false,
      listName: "UtilitiesContracts",
      CAMLQuery: myQuery,
      CAMLRowLimit: 100,
      completefunc: function(xData, Status) {
        var liHtml = "<tbody>";
        $(xData.responseXML).SPFilterNode("z:row").each(function() {
          liHtml = liHtml + " <tr><td>" + $(this).attr("ows_Client") + "</td><td>" + $(this).attr("ows_Title1") + "</td><td>" + $(this).attr("ows_Title2") + "</td><td>" + $(this).attr("ows_Title3")+ "</td></tr>";
        });
        liHtml += "</tbody>";
        $("#example").append(liHtml);
      }
    });
    $('#example').DataTable({
      "dom": 'Rlfrtip'
    });
  });

</script>
<table id="example" class="display" cellspacing="0" width="100%">
  <thead>
    <tr>
      <th>Client</th>
      <th>Title1</th>
      <th>Title2</th>
      <th>Title3</th>
    </tr>
  </thead>
</table>

enter image description here

如果要从本地访问SharePoint列表数据,我们可以使用CSOM(C#)来实现。

Complete basic operations using SharePoint client library code