【问题标题】:DataTables -- Filter Table Data by Parameter given by URLDataTables -- 按 URL 给出的参数过滤表数据
【发布时间】:2016-08-04 16:12:53
【问题描述】:

我知道还有很多其他问题与这个问题有关,但我还没有找到一个与我的问题完全吻合的问题。我正在使用 angularjs、express、html 和 jquery。我有一个数据表结构,可以查询文件夹的子目录,然后能够在选定的子目录中显示数据。子目录命名法是客户端的id,子目录中的数据是文档。在数据表所在的页面上,我以这种格式发送了一个参数:domain/client/:id。在角度方面,我已经能够捕捉到这个参数并过滤其他结果。但是,我不太确定如何在我的数据表中。我确实知道如何过滤数据表中显示的结果,这不是问题。问题是捕获此参数,然后将其传递给我的过滤器函数。这是我的数据表的代码:

$(document).ready(function() {
    var table = $(".linksholder").dataTable({
        "fnCreatedRow": function(nRow, aData, iDataIndex) {
            if (!aData.IsDirectory) return;
            var path = aData.Path;
            $(nRow).bind("click", function(e) {
                $.get('/files?path=' + path).then(function(data) {
                    table.fnClearTable();
                    table.fnAddData(data);
                    currentPath = path;
                });
                e.preventDefault();
            });
        },
        "aoColumns": [{
            "sTitle": "",
            "mData": null,
            "bSortable": false,
            "sClass": "head0",
            "sWidth": "55px",
            "render": function(data, type, row, meta) {
                if (data.IsDirectory) {
                    return "<a href='#' target='_blank'><i class='fa fa-folder'></i>&nbsp;" + data.Name + "</a>";
                } else {
                    return "<a href='/assets/" + data.Path + "' target='_blank'><i class='fa " + "'></i>&nbsp;" + data.Name + "</a>";
                }
            }
        }],
    });
    $.get('/files').then(function(data) {
        table.fnClearTable();
        table.fnAddData(data);
    });
    $(".up").bind("click", function(e) {
        if (!currentPath) return;
        var idx = currentPath.lastIndexOf("/");
        var path = currentPath.substr(0, idx);
        $.get('/files?path=' + path).then(function(data) {
            table.fnClearTable();
            table.fnAddData(data);
            currentPath = path;
        });
    });
});

【问题讨论】:

  • 您应该将其设为指令,然后您就可以通过scope 和指令上的属性将参数传递给它。这里有很多关于在 Angular 中使用带有指令的 jQuery 的帖子。

标签: jquery angularjs datatable


【解决方案1】:

这里是解决方案:

我添加了这些变量:

var url = window.location.href;
var id = document.location.href.split('client/')[1];

然后这样调用具体的子目录:

 $.get('/files?path=' + id).then(function(data) {
          table.fnClearTable();
          table.fnAddData(data);

        });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 2015-10-25
    • 2017-02-08
    • 2017-01-07
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    相关资源
    最近更新 更多