HTML表格未正确引用共享点列表

时间:2018-07-02 12:13:03

标签: javascript html sharepoint

我试图将数据从Sharepoint列表中拉到单独的HTML表中。我已经通过Javascript为每个单独的表创建了一个连接,但是,它似乎并没有将数据带入表中。

我运行以下代码约10次以链接到不同的表头。

  <script language="javascript" type="text/javascript">
    $(document).ready(function() {
    var myQuery =
      "<Query>" +
      "<Where><Eq><FieldRef Name='Client'/><Value Type='Text'>Bristol Water</Value></Eq></Where>"+
      "<OrderBy>" +
      "<FieldRef Name='Client' />" +
      "</OrderBy>" +
      "</Query>";
    $().SPServices({
      webURL: "https://ext.kier.group/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_ContractName")+ "</td><td>" + $(this).attr("ows_ContractDescription")+ "</td><td>" + $(this).attr("ows_OperationalContacts")+ "</td><td>"$(this).attr("ows_CommercialContacts")+ "</td></tr>";
        });
        liHtml += "</tbody>";
        $("#BristolTable").append(liHtml);
      }
    });
    $('#BristolTable').DataTable({
      "dom": 'Rlfrtip'
    });
  });
</script>

1 个答案:

答案 0 :(得分:0)

您在上面的代码中缺少“ +”。

下面的完整代码供您参考:

<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>" +
  "<Where><Eq><FieldRef Name='Client'/><Value Type='Text'>Bristol Water</Value></Eq></Where>"+
  "<OrderBy>" +
  "<FieldRef Name='Client' />" +
  "</OrderBy>" +
  "</Query>";
$().SPServices({
  webURL: "https://ext.kier.group/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_ContractName")+ "</td><td>" + $(this).attr("ows_ContractDescription")+ "</td><td>" + $(this).attr("ows_OperationalContacts")+ "</td><td>"+$(this).attr("ows_CommercialContacts")+ "</td></tr>";
    });
    liHtml += "</tbody>";
    $("#ContractsTable").append(liHtml);
  }
});
$('#ContractsTable').DataTable({
  "dom": 'Rlfrtip'
});
});
</script>
<table id="ContractsTable" class="display" cellspacing="0">
  <thead>
    <tr>
      <th>Client</th>
      <th>Contact Name</th>
      <th>Contact Description</th>
      <th>Operational Contacts</th>
      <th>Commercial Contacts</th>
    </tr>
  </thead>
</table>