2017-07-06 56 views
0

我检索基于用户ID与下面的脚本从API两个日期之间的过滤器,angularjs

$http.post("http://testingserver.net/statement.php",{'id':$scope.account_number}).success 
    (function(data){ 
    console.log(JSON.stringify(data)); 
$scope.statement=data; 
    }); 

从日志中我能得到详细数据的API声明的帐户的详情。来自日志的数据包含一个名为Date的字段,格式为2017-02-01T00:00:00Z,我想要实现的是让用户从两个日期范围中进行选择并将结果推回给用户。

从HTML低于它们是两个领域,即sdateedate

HTML

<form method="post" name="statement" id="statement"> 
<div class="list"> 
    <label class="item item-input"> 
    <span class="input-label">Search From</span> 
    <input type="date" ng-model="sdate"> 
    </label> 
    <label class="item item-input"> 
    <span class="input-label">Search To</span> 
    <input type="date" ng-model="edate"> 
    </label> 
</div> 
</form> 
</br> 
<div align="center"> 
<p><button class="button button-positive" ng-disabled="statement.$invalid" ng-click="state_request()"> 
    <i class="icon ion-android-search icon"></i> Search 
</button></p> 
</div> 

HTML的结果

<div ng-repeat="item in statement"> 
    <table width="100%" border="0" cellspacing="5" cellpadding="5"> 
    <tr> 
     <td width="70%"><div align="left"> 
     <p><strong> Period</strong>  </p> 
     </div></td> 
     <td width="82%">{{item.Date |date: 'MMMM yyyy'}}</td> 
    </tr> 
    <tr> 
     <td><p><strong>Category</strong></p></td> 
     <td>{{item.Category}}</td> 
    </tr> 
    <tr> 
     <td><div align="left"> 
     <p><strong>Amount</strong>  </p> 
     </div></td> 
     <td><div align="left">{{item.Amount}}</div></td> 
    </tr> 
    <tr> 
     <td colspan="2">&nbsp;</td> 
    </tr> 
    </table> 
</div> 

回答

0

我们需要的功能,为我们的businees逻辑和通过sadte和EDATE:你可以试试这个:

state_request = function(sdate,edate){ 
    if(new Date(sadte) < new Date(edate)){ 
    // now write here the web service logic 
    //$http.post('domain/startDate=sadte&endDate=edate'){ 

    }.then(function(req,res){ 
    //bind your html variable from here like, res.a,res.b etc 
    }); 
    } 
    } 
0

你有两条路走:
1)添加开始/结束日期并使用服务器进行繁重的工作。
2)发回所有结果并过滤客户端。

前者可能是最好的选择。如果你这样做,你需要日期sdate和edate在你的url的查询参数,该服务器将处理,然后有某种存储过程做日期范围检查。我不是一个PHP的家伙--Java是我的特长,Angular 4/Ionic。

相关问题