【问题标题】:js get html datatable pointer from another functionjs从另一个函数获取html数据表指针
【发布时间】:2015-02-25 11:47:05
【问题描述】:

我正在处理 django 表,我的主页正在使用 databaleview 显示一个表。

我正在尝试在我的 html 中创建一个 js 函数,它会在表格结束后再次绘制表格。

我的主要 html 中的相关部分:

<div class="row">

        {{ datatable }}
        <button name="me" id="changeread" type="button">Read / Unread</button>

    </div>


<script>
   $( function() {
        var xeditable_options = {};
        var table = datatableview.initialize($('.datatable'),
                {

                    lengthMenu : [ [10, 20, 50, 100, -1 ], [10, 20, 50, 100, "All" ] ],
                    fnRowCallback:
                            datatableview.make_xeditable(xeditable_options),

                    bProcessing : true

                }
        );

这是我想在表格结束后重绘表格的功能:

 function myIpfunc(d){
        if( !confirm( "Are you sure you want to do this to -> " + d + " <- ?" ) ){
                return;
            }
        var table = $(this).DataTables_Table_0_wrapper;
        #var table = $(this).datatable #didnt work also
        table.draw()

在它所在页面的检查元素选项中:

<div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">

知道我应该如何处理“var table = 吗?”

【问题讨论】:

    标签: javascript jquery django datatables


    【解决方案1】:

    您可以将 table 变量设为全局变量,以便在其他函数中重复使用:

    <script>
       var table;
       $( function() {
            var xeditable_options = {};
            table = datatableview.initialize($('.datatable'),
            ...
    

    那么你的函数就变成了:

    function myIpfunc(d) {
        if( !confirm( "Are you sure you want to do this to -> " + d + " <- ?" ) ){
                return;
            }
        table.draw();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-09
      相关资源
      最近更新 更多