首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Smart-table:按列中的多个属性进行搜索

Smart-table:按列中的多个属性进行搜索
EN

Stack Overflow用户
提问于 2015-11-04 15:57:05
回答 1查看 1.1K关注 0票数 3

我已经在我的angular项目中实现了一个智能表。目前,我在一个数组中有许多人。

代码语言:javascript
复制
$scope.persons = [
    {
        "firstname":"Anders",
        "lastname":"Andersson",
        "city":"Stockholm",
        "country":"Sweden"
    },
    {
        "firstname":"John",
        "lastname":"Smith",
        "city":"Washington DC",
        "country":"USA"
    }
];

我已经把它绑定到我的桌子上了。

代码语言:javascript
复制
<table st-safe-src="persons" class="table">
    <thead>
        <tr>
            <th><input st-search="firstname" class="form-control" type="search"/></th>
            <th><input st-search="lastname" class="form-control" type="search"/></th>
            <th><input st-search="city" class="form-control" type="search"/></th>
            <th><input st-search="country" class="form-control" type="search"/></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="person in persons">
            <td>{{person.firstname}}</td>
            <td>{{person.lastname}}</td>
            <td>{{person.city}}</td>
            <td>{{person.country}}</td>
        </tr>
    </tbody>
</table>

这项工作非常顺利。在每一列的每个标题中,我都可以搜索指定的属性。但是,我想重做该表,并在同一列中有两个(或者将来可能会有更多)属性。在我相当简单的示例中,我想将我的城市和国家属性连接到一个列中,如下所示。

代码语言:javascript
复制
<table st-safe-src="persons" class="table">
    <thead>
        <tr>
            <th><input st-search="firstname" class="form-control" type="search"/></th>
            <th><input st-search="lastname" class="form-control" type="search"/></th>
            <th><input st-search="???" class="form-control" type="search"/></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="person in persons">
            <td>{{person.firstname}}</td>
            <td>{{person.lastname}}</td>
            <td>{{person.city}}, {{person.country}}</td>
        </tr>
    </tbody>
</table>

在此更改中,我希望在第三列中同时搜索城市和国家。要实现该功能,我必须做些什么?

EN

回答 1

Stack Overflow用户

发布于 2015-11-29 17:49:15

这里有一个想法(我打赌你可以用其他几种方式实现这种功能)。

在智能表中,您可以为您希望执行的任何操作定义数据的安全副本,而无需使用st-safe-src属性修改数据。在安全集合中,将城市和国家字符串连接到一个新属性上。

person.location: [person.city, person.country].join(', ');

或者只是在将表数据传递给smart-table之前修改它

然后根据新的'location‘属性st-search="location"进行过滤

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33516498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档