AngularJS过滤json数据

时间:2015-01-17 08:52:37

标签: angularjs

我在mysql数据库中有一个名为" month" 1月为1,2月为2,依此类推。

在我的AngularJS应用程序中,我使用get请求从我的php文件中提取json数组。有没有办法过滤"数据"所以我只能请求包含列月份的帖子,这将允许我做一个if语句,例如if(month == 1){filter only data of month value value 1}

到目前为止,这是我的代码:

app.controller('TimeController', function($scope, $filter, $http) {
  $http.post('ajax/getQuotes.php').success(function(data){

      $scope.monthNumber = $filter('date')(new Date(), 'M');

    if ($scope.monthNumber == 1){


    }

     $scope.quote = data;


     angular.element(document.getElementById('log')).html(   $scope.monthNumber);


  });

这是我的PHP代码:

<?php
include('../includes/config.php');

try {

    //Connect to the database, store the connection as a PDO object into $db.
    $db = new PDO("mysql:dbname=".$DB_NAME.";host=".$DB_HOST.";charset=utf8", $DB_USER, $DB_PASS );

    //PDO will throw PDOExceptions on errors, this means you don't need to explicitely check for errors.
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    //PDO will not emulate prepared statements. This solves some edge cases, and relives work from the PDO object.
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

    //Prepare the statement.
    $statement = $db->prepare("SELECT * FROM quotes");

    //Execute the query
    $statement->execute();

    //Fetch all of the results.
    $result = $statement->fetchAll(PDO::FETCH_ASSOC);
    //$result now contains the entire resultset from the query.

    //create a temp array
    $arr = array();

    //loop through mysql tables
    if ($statement->execute()) {
        while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
            $arr[] = $row;
        }
    }
    array_unshift($arr, null);
    echo json_encode($arr);



    /*** close the database connection ***/
    $db = null;
}
catch(PDOException $e)
{
    echo $e->getMessage();
}




?>

是否可以为每个循环执行a并推送json数据?

$.each {      if $scope.quote.month  == 1){          items.push ;         }  }

0 个答案:

没有答案