gpt4 book ai didi

javascript - Angular js : How to call multiple asynchronous http request one after another and store the respone for later use?

转载 作者:行者123 更新时间:2023-12-03 12:23:50 26 4
gpt4 key购买 nike

请帮忙:((失望)

我的 mysql 数据库中有一个表,用于存储 avalabe 读书时间;

在我的网站中,有一些按钮,用户可以点击并获取相关的可用图书时间,您可以在附图中看到。

enter image description here

每次用户点击左/右箭头时,我都会触发一个工厂函数,然后我会得到一个包含与当天相关的avalabe书籍的数据,到目前为止一切正常。

问题:当用户第一次进入我的网站时,我将获取当前日期,并显示与当天(今天)相关的可用图书时间,当用户点击左/右箭头时,我将获取与相关的可用图书时间从今天起三天后。这也很好用。

但这

我希望当用户进入我的网站时,我可以获得与今天相关的数据直到两个月后。

但我只想展示今天(以及第二天和接下来的 2 天)的 avalabe 书籍。因此,当用户单击左/右箭头时,我不必调用另一个 http 请求并强制用户等待我的数据可供查看。

有没有办法定义一些异步http请求并存储回调成功数据,但在用户按下特殊键(在我的例子中是左/右箭头)之前不要使用它???

这是我在工厂中的 http 请求函数:

     app.factory('ShowBookingFacDrProfile',function($http){
return{
showbooking:function(scope){
$http.post("partials/search-drprofile/show_available_books.php",{today,nextday,next2day})// I just simplicized the object that I send here
.success(function(msg){
scope.booking=msg;;
//here I want to do something like this :
then.post('sameURL',{next3day,next4day,next5day})
// I want to repeat this until 2 month later from today
then.post('sameURL',{next6day,next7day,next8day})

}
}
});

相关 Controller :

    $scope.hitArrow = function(current) {
$scope.pager = current;
SearchFac.search($scope);
};

在我的 Controller 中注意到特殊

我知道我可以使用 Promise ! ,但是如何存储它们呢?在哪里?以后怎么用?

我无法将它们存储在新的scope.booking中,例如:scope.booking2,因为这样我就无法正确使用它们:(

我无法使用缓存,因为也许每分钟 avalabe 书籍都会发生变化:(

这是我的观点:

   <div class='col-xs-4'>
<table class='table table-responsive' >
<tr data-ng-repeat='v in booking |filter:{month:date.next2month} |filter:{day:date.next2day}'>
<td><a>{{v.hour}}</a></td>
</tr>
</table>
</div>

<div class='col-xs-4'>
<table class='table table-responsive' >
<tr data-ng-repeat='v in booking |filter:{month:date.nextmonth} |filter:{day:date.nextday}'>
<td><a>{{v.hour}}</a></td>
</tr>
</table>
</div>

<div class='col-xs-4'>
<table class='table table-responsive' >
<tr data-ng-repeat='v in booking |filter:{month:date.today} |filter:{day:date.today}'>
<td><a>{{v.hour}}</a></td>
</tr>
</table>
</div>

注意实际上我在这个网站上看到过这种方法 Click

请查看并点击箭头您将看到新的可用图书时间进入 View 的速度有多快

最佳答案

如果 $scope. booking 是一个数组,您只需附加 http 响应的内容 (array.push(object))。

关于javascript - Angular js : How to call multiple asynchronous http request one after another and store the respone for later use?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24316956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com