I am facing a challenge with two arrays in my code. The first array, $scope.termini
, contains strings, and the other one, $scope.reserved
, contains objects. Each object in the second array has a variable called vrijemeTermina
. My goal is to filter $scope.termini
based on the values of
$scope.reserved[x].vrijemeTermina
.
reserve.controller('resCtrl', function($scope, $http) {
$scope.$watch("pickedDate", function(){
$scope.termini=["13:00","15:00","17:00","19:00","21:00"];
$http.post('php/dropdown.php',{"datum":$scope.pickedDate}).success(function(data){
$scope.reserved = data;
//alert(JSON.stringify(data));
//alert($scope.reserved[0].datumTermina);
angular.forEach($scope.reserved, function(value, key){
$scope.termini = $filter('filter')($scope.termini, value.vrijemeTermina, false);
});
});
console.debug("%o", $scope.termini);
});
});
I have tried multiple approaches to solve this issue without success. Most solutions I come across involve filtering object arrays based on their properties, but I have not yet found a suitable solution for my specific problem.
<?php
require_once(dirname(dirname(__FILE__))."/php/db-conn.php");
$data = json_decode(file_get_contents("php://input"));
$query = "SELECT * from termin WHERE datumTermina='".$data->datum."'";
$result = mysqli_query($con, $query);
$arr = array();
if(mysqli_num_rows($result) != 0) {
while($row = mysqli_fetch_assoc($result)) {
$arr[] = $row;
}
}
$con->close();
echo json_encode($arr);
?>
This is my PHP file that returns JSON data in the format
{0:{"id":"1";"vrijemeTermina":"13:00";"datumTermina":"03/09/2016"}}
as far as I can tell.