【问题标题】:Init filter of tableParams with a compound name issue具有复合名称问题的 tableParams 的初始化过滤器
【发布时间】:2014-07-16 20:48:54
【问题描述】:

当我像这样使用 ng-init 初始化表时:

<table ng-table="tableParams" template-pagination="custom/pager" template-header="custom/header" ng-init="tableParams.filter({name:'George Harrison'})" show-filter="true" class="table">

这个词摆在桌面上。该表不显示任何项目。但是当我只输入单词“George”(没有空格)时,项目就会出现。

我该如何解决这个问题?谢谢。

【问题讨论】:

    标签: angularjs filter ngtable


    【解决方案1】:

    定义tableParams时,可以设置initial filter value

    $scope.tableParams = new ngTableParams({
        page: 1,            
        count: 10,          
        filter: {
            name: 'George Harrison'       // initial filter
        }
    }, {
    ...
    

    但是,如果您必须使用ng-init,正确的语法应该是:

    ng-init="tableParams.filter()['name'] = 'George Harrison'"
    

    更新:

    如果你想试试这个代码,here is a working plunker

    【讨论】:

    • 好的,这确实有效。但是,这只是在列过滤器的文本字段中插入该字符串并使用设置了此过滤器的表开始。但问题仍然存在。如果字符串是复合的,则过滤器不显示任何内容。
    • 我在测试时没有体验到这一点。我将用一个 plunker 更新我的答案,证明这在真空中有效。
    猜你喜欢
    • 2016-09-22
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    • 2011-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多