筛选共享点列表

时间:2018-06-22 12:25:51

标签: javascript html list sharepoint

当在html表中显示我的列表时,如果它等于某物,我只想引入该列表中的项目。例如,如果客户等于x,则输入与其关联的联系方式。

我目前的代码在下面,仅包含特定列,例如client等。

任何帮助将不胜感激。

<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: "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_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" width="50%">
  <thead>
    <tr>
      <th>Client</th>
      <th>Operational Contacts</th>
	  <th>Commercial Contacts</th>
    </tr>
  </thead>
</table>

<a href="">News</a>
<br>
<a href="">Operational</a>

2 个答案:

答案 0 :(得分:0)

您需要在条件条件下使用CAML查询。在Where条件中,您可以传递客户端的名称。检查以下示例代码:

var myQuery = "<Query><Where><Eq><FieldRef Name='Client'/><Value Type='Text'>" + X +  "</Value>
</Eq></Where><OrderBy><FieldRef Name='Client' /></OrderBy></Query>"

现在,您可以在SPServices代码中使用此myQuery,它将过滤出结果。

答案 1 :(得分: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'>X</Value></Eq></Where>"+
      "<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_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" width="50%">
  <thead>
    <tr>
      <th>Client</th>
      <th>Operational Contacts</th>
      <th>Commercial Contacts</th>
    </tr>
  </thead>
</table>

<a href="">News</a>
<br>
<a href="">Operational</a>