2017-04-26 65 views
0

如何重绘或销毁我在xhtml中声明的数据表。我尝试了一切,但它不起作用。在JSF中操作JQuery中的DataTable

这是我的数据表:

<h:dataTable id= "book" var="book" value="#{bean.booksByAuthor}" rowClasses="even-row,odd-row"> 
       <h:column> 
        <f:facet name="header">Title</f:facet> 
        <h:outputText value="#{book.title}" class=""/> 
       </h:column> 
       <h:column> 
        <f:facet name="header">ISBN</f:facet> 
        <h:outputText value="#{book.ISBN}"/> 
       </h:column> 
       <h:column> 
        <f:facet name="header">Price</f:facet> 
        <h:outputText value="#{book.price}"/> 
       </h:column> 
       <h:column> 
        <h:commandButton value="Buy" action="buyItem"> 
         <f:param name="book2Buy" value="#{book.ISBN}" /> 
        </h:commandButton> 
       </h:column> 
      </h:dataTable> 

而且这是我正在试图访问它在我的脚本:

<script> 
     function change() { 
      event.preventDefault(); 
      $('#f:\\book').DataTable().clear(); 
      $('#f:\\book').DataTable().destroy(); 
     } 
    </script> 

这是我进口:

<script type="text/javascript" src="scripts/jquery-3.2.1.js"></script> 
    <script type="text/javascript" src="scripts/jquery-ui-1.12.1/jquery-ui.js"></script> 

    <!-- Data Table--> 
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-2.2.4/dt-1.10.15/datatables.min.css"/> 
    <script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-2.2.4/dt-1.10.15/datatables.min.js"></script> 

我甚至尝试访问此表,如$("$book),并致电htmlappend它。但没有任何工作。我甚至没有任何错误。

任何建议/建议?

+0

首先阅读[如何使用jQuery选择JSF组件?](http://stackoverflow.com/questions/7927716/how-to-select-jsf-components-using-jquery) –

回答

0

如果您尝试使用jquery获取元素$('#f:\\book')不会工作,因为您正在寻找一个名为f:\ book的ID。

如果你想在jQuery的你应该尝试选择的书直接

function change() { 
    event.preventDefault(); 
    $('#book').DataTable().clear(); 
    $('#book').DataTable().destroy(); 
} 

而且删除ID之间的空间中的数据表=和“书”

+1

如果''在''中,数据表的实际客户端ID是'f:book'。 ':'需要被转义,这很可能是OP使用'#f:\\ book'错误地尝试的方式 – Kukeltje