使用Json Txt文件中的JQuery.grep在PHP中过滤结果

时间:2014-12-05 21:22:43

标签: javascript php jquery json grep

我能够毫无问题地将我的JSON结果提取到我的表中,但是当根据我的PHP $_GET变量过滤结果时,我似乎无法返回结果集。

我的表很简单:

<table id="displaythatdata">
  <thead>
    <tr>
      <th>Meter</th>
      <th>Address</th>
      <th>City</th>
      <th>Date</th>
      <th>Status</th>
      <th>Location</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>that</td>
      <td>that2</td>
      <td>that3</td>
      <td>that4</td>
      <td>that5</td>
      <td>that6</td>
    </tr>
  </tbody>
</table>

我的jQuery函数看起来像这样。我只是试图在我的表中附加我使用PHP设置的$_GET变量的结果:

Json_return = [];

jQuery(function(){
  jQuery.getJSON('./json/acm2.txt',{},function(data){

    Json_return = data;
    jQuery('#displaythatdata').eq(0).html('');
    jQuery(Json_return).each(function(indx,Val){

      var returnedData = $.grep(Json_return, function(element, index){

        return element.PLAT = <?php echo $getthedivision ?>;
        return element.DIVISION  = <?php echo $getthedivision ?>;


        jQuery('#displaythatdata').eq(0).append('<tr>
                <td>'+returnedData.METER+'</td><td>'+returnedData.LOCADDRESS+'</td>
                <td>'+returnedData.CITY+'</td><td>'+returnedData.INSPECTION_DATETIME+'</td>
                <td>'+returnedData.INSPECTION_STATUS+'</td><td>'+returnedData.LOC+'</td>
                </tr>');
      });
    });
  });

我的PHP是标准的:

$getthedivision = $_GET['getregion'];
$gettheplat = $_GET['getplat'];

我的JSON看起来像:

[{"ID":1,"UUID":"5D2F830-8757-F80FA715A78E","SPID":86810,"METER":"900A","LOCADDRESS":"123 MEADOW RD","CITY":"SANTA ANA","DIVISION":"SAN DIEGO","PLAT":"1145-C08","ADDRESS_NUM":123,"ADDRESS_EVODD":1,"ADDRESS_STREET":"MEADOW RD","GRD_BELOW_SU":null,"GRD_ABOVE_SU":null,"MANIFOLD_METER":null"},

关于为什么我可以根据我的PHP $_GET变量返回结果集的任何想法?我能够将它们打印出来,所以我知道它们已经被设置好了。我看到.grep()是使用jQuery JSON过滤的方法。这也是对象的情况吗?

0 个答案:

没有答案