K
K
KOPC18862014-11-24 13:28:35
PHP
KOPC1886, 2014-11-24 13:28:35

How to filter a list of elements?

Hello!
There is such an array in php

$arResult = array();
        $arResult['applications_type'] = array(
            array(
                'id' => 65,
                'name' => 'Документы'
            ),
            array(
                'id' => 89,
                'name' => 'Обучение'
            ),
            array(
                'id' => 111,
                'name' => 'Командировку'
            )
        );

        for($i = 0; $i <= 5; $i++)
        {
            $arResult['applications'][65][$i] = array(
                'id' => $i,
                'name' => 'Справка с места работы',
                'task' => array(
                    'id' => $i,
                    'name' => 'Заполните форму',
                    'link' => ''
                ),
                'actions' => array(
                    array(
                        'label' => 'Подробнее',
                        'link' => ''
                    ),
                    array(
                        'label' => 'Остановить',
                        'link' => ''
                    )
                )
            );

            $arResult['applications'][89][$i] = array(
                'id' => $i,
                'name' => 'Завка на обучение',
                'task' => array(
                    'id' => $i,
                    'name' => 'Заполните форму',
                    'link' => ''
                ),
                'actions' => array(
                    array(
                        'label' => 'Подробнее',
                        'link' => ''
                    ),
                    array(
                        'label' => 'Остановить',
                        'link' => ''
                    )
                )
            );

            $arResult['applications'][111][$i] = array(
                'id' => $i,
                'name' => 'Завка на командировку',
                'task' => array(
                    'id' => $i,
                    'name' => 'Заполните форму',
                    'link' => ''
                ),
                'actions' => array(
                    array(
                        'label' => 'Подробнее',
                        'link' => ''
                    ),
                    array(
                        'label' => 'Копировать',
                        'link' => ''
                    ),
                    array(
                        'label' => 'Продлить',
                        'link' => ''
                    ),
                    array(
                        'label' => 'Сократить',
                        'link' => ''
                    ),
                    array(
                        'label' => 'Изменить',
                        'link' => ''
                    ),
                    array(
                        'label' => 'Удалить',
                        'link' => ''
                    ),
                    array(
                        'label' => 'Остановить',
                        'link' => ''
                    )
                )
            );
        }

I output $arResult['applications_type'] to , and $arResult['applications'] to a table.
<div class="block_search_app">
            <span class="app_name">Заявки на </span>
            <select class="select_app">
                <option value="{{type.id}}" ng-repeat="type in types">{{type.name}}</option>
            </select>
        </div>
        <table class="table_applications" id="TableApplications">
            <thead>
                <th class="app name">Название заявки</th>
                <th class="app status">Статус заявки</th>
                <th class="app task">Задание</th>
            </thead>
            <tbody>
                <tr class="bid" ng-repeat="doc in applications | filter">
                    <td class="name">{{doc.name}}</td>
                    <td class="status">
                        <span class="status work"></span>
                        В работе
                    </td>
                    <td class="task">
                        <a href="{{doc.task.link}}" class="task_link"><b>{{doc.task.name}}</b></a>
                    </td>
                </tr>

How can I make the list in the table change when a certain value is selected in the select?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Mishin, 2014-11-24
@sergeysmishin

It is not clear how the array types and applications are related.
If each application element had a type field equal to one of the values ​​of the types array, then there would be such a solution.

<div class="block_search_app">
            <span class="app_name">Заявки на </span>
            <select ng-model="type" class="select_app">
                <option value="">Все</option>
                <option value="{{type.id}}" ng-repeat="type in types">{{type.name}}</option>
            </select>
        </div>
        <table class="table_applications" id="TableApplications">
            <thead>
                <th class="app name">Название заявки</th>
                <th class="app status">Статус заявки</th>
                <th class="app task">Задание</th>
            </thead>
            <tbody>
                <tr class="bid" ng-repeat="doc in applications | filter:type">
                    <td class="name">{{doc.name}}</td>
                    <td class="status">
                        <span class="status work"></span>
                        В работе
                    </td>
                    <td class="task">
                        <a href="{{doc.task.link}}" class="task_link"><b>{{doc.task.name}}</b></a>
                    </td>
                </tr>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question