【问题标题】:Angular filter second-level object角度过滤器二级对象
【发布时间】:2014-02-12 16:40:07
【问题描述】:

我有一个如下所示的数组:

$scope.orders = [
    {
        id: 1,
        costumer_id: 1,
        product_id: 1,
        quantity: 2,
        costumer:
        {
            id: 1,
            name: John Doe,
            age: 47,
            state: Georgia,
            province: Atlanta
        }
    },
];

我想做的是创建 3 个输入来按客户姓名、客户所在州或客户所在省份对其进行过滤。这就是我正在做的事情:

<tr ng-repeat="order in orders | filter:search">
    <td class="text-muted">{{ order.id }}</td>
    <td>{{ order.costumer.name }}</td>
    <td>{{ order.costumer.state }}</td>
    <td>{{ order.costumer.province }}</td>
    <td>
        {{ order.product_id }}
        <span class="label label-info">{{ order.quantity }} unidades</span>
    </td>
</tr>

以及要过滤的输入:

<input class="form-control input-sm" type="text" ng-model="search.$" placeholder="search for everything">
<input class="form-control input-sm" type="text" ng-model="search.costumer.name" placeholder="filter by name">
<input class="form-control input-sm" type="text" ng-model="search.costumer.state" placeholder="filter by state">
<input class="form-control input-sm" type="text" ng-model="search.costumer.province" placeholder="filter by province">

只有第一个输入过滤器有效,其他输入过滤器无效!我该如何进行这种过滤?!

谢谢!

【问题讨论】:

标签: javascript angularjs angularjs-filter


【解决方案1】:

如果您在 IE 中进行测试,我认为这可能是因为 $scope.orders 在数组末尾有一个尾随逗号。

我在这里为此创建了一个 Plunkr:http://plnkr.co/edit/P1LVvgjsRUYu9Z8cHGpR?p=preview

【讨论】:

    猜你喜欢
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-17
    相关资源
    最近更新 更多