Combination of javascript function

Asked

Viewed 65 times

0

Hello, I have two functions that work separately very good, but I need to combine them now to organize the result of the other. Function of Organs:

$scope.$watch('organ_id', function (newValue, oldValue) {
    if (newValue != null && newValue != '') {
       $scope.servicesPromise =
          $http
            .get('/api/services.json?organ_id=' + newValue)
              .success(function (data) {
                $scope.total_pages = data.total_pages;
                $scope.services = data.services;
            });
        };
    }, true);

Function by letters

$scope.byLetter = function (letter) {
      $scope.servicesPromise =
          $http
            .get('/api/services.json?letter=' + letter)
              .success(function (data) {
                    $scope.total_pages = data.total_pages;
                    $scope.services = data.services;
            $scope.tama_letra = data.tam_letter;
                });
    };

The function of organs behind a set and what I wish is that when I select the order by letters the return is only the services of that given organ with that letter.

for example: Whether I chose organ X; I have as return SX services; in this set I want to know which services that initial with the letter E; I choose the letter E; I need the answer, in this case are the SX that start with E.

  • Your service accepts the two combined parameters?

  • Yes, the function accepts!

  • So it wouldn’t just be making a call with the two parameters?

  • Just, in the combination I imagine, the parameters would be (organ_id, Letter).

  • All right, I’ll write a response based on that then

1 answer

0


You can request with two parameters:

function _search(organ_id, letter) {
  var params = {};

  params.organ_id = organ_id;
  params.letter = letter;

  return $http.get('/api/services.json', {params: params}).success(function(data) {
    $scope.total_pages = data.total_pages;
    $scope.services = data.services;
  });
}
  • Show, man, it was worth it!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.