How to get the information in a select depending on what you have selected from another select?

1

I'm doing a crud of employees, in the employee creation form I have 2 select. The first selection is that of departments, therefore it displays, for example (Dpt. Audit, Informatics, Warehouse, etc). And the second select is that of posts, therefore it returns all the posts that exist.

//Select departamentos
        $scope.ObjDepartamentos = {};
        $scope.departamentos    = [];

        $http.get(server+'ws/departamentos').success(function(datas)
        {
            angular.forEach(datas.records, function(value, key)
            {   
                $scope.departamentos.push({
                    id:         value.id,
                    title:      value.nombre,
                    value:      value.id,
                    parent_id:  value.id 
                });
            });
        });

        $scope.ObjDepartamentos['departamentos'] = $scope.departamentos;

        $scope.confDepartamentos = {
            create: false,
            maxItems: 1,
            placeholder: 'Departamentos...',
            optgroupField: 'parent_id',
            optgroupLabelField: 'title',
            optgroupValueField: 'ogid',
            valueField: 'value',
            labelField: 'title',
            searchField: 'title'
        };
        //----------------------

HTML:

<input type="text" config="confDepartamentos" options="ObjDepartamentos.departamentos" ng-model="item.iddepartamento" name="iddepartamento" selectize />

Second select:

//Select puestos
            $scope.ObjPuestos = {};
            $scope.puestos    = [];

            $http.get(server+'ws/puestos').success(function(datas)
            {
                angular.forEach(datas.records, function(value, key)
                {   
                    $scope.puestos.push({
                        id:         value.id,
                        title:      value.nombre,
                        value:      value.id,
                        parent_id:  value.id 
                    });
                });
            });

            $scope.ObjPuestos['puestos'] = $scope.puestos;

            $scope.confPuestos = {
                create: false,
                maxItems: 1,
                placeholder: 'Puestos...',
                optgroupField: 'parent_id',
                optgroupLabelField: 'title',
                optgroupValueField: 'ogid',
                valueField: 'value',
                labelField: 'title',
                searchField: 'title'
            };
            //----------------------

HTML:

<input type="text" config="confPuestos" options="ObjPuestos.puestos" ng-model="item.idpuesto" name="idpuesto" selectize />

I want to know how: when selecting for example the computer department in the second select only show me the positions that are related to the computer department, it is worth mentioning that in another table I create the posts related to a department .

    
asked by JG_GJ 02.03.2018 в 07:04
source

1 answer

0

What a friend.

It is probably not necessary to make two calls to resources. On the first call you could return a JSON object with a format similar to:

[
    {
        nombre: "Auditoría"
        puestos: ["Director", "Gerente", "Auditor de Sistemas"]
    },
    {
        nombre: "Informática"
        puestos: ["Líder de proyecto", "Desarrollado]
    }
]

From AngularJS you would filter by value of the property "name" (or a property with ID) to obtain its respective vector of posts.

    
answered by 02.03.2018 в 07:35