久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='8gtCR'><style id='8gtCR'><dir id='8gtCR'><q id='8gtCR'></q></dir></style></legend>

        <tfoot id='8gtCR'></tfoot>

          <bdo id='8gtCR'></bdo><ul id='8gtCR'></ul>

        <small id='8gtCR'></small><noframes id='8gtCR'>

      1. <i id='8gtCR'><tr id='8gtCR'><dt id='8gtCR'><q id='8gtCR'><span id='8gtCR'><b id='8gtCR'><form id='8gtCR'><ins id='8gtCR'></ins><ul id='8gtCR'></ul><sub id='8gtCR'></sub></form><legend id='8gtCR'></legend><bdo id='8gtCR'><pre id='8gtCR'><center id='8gtCR'></center></pre></bdo></b><th id='8gtCR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8gtCR'><tfoot id='8gtCR'></tfoot><dl id='8gtCR'><fieldset id='8gtCR'></fieldset></dl></div>

        Ionic 3 - 使用異步數據更新 Observable

        Ionic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用異步數據更新 Observable)

        <tfoot id='iHuOC'></tfoot>

        <legend id='iHuOC'><style id='iHuOC'><dir id='iHuOC'><q id='iHuOC'></q></dir></style></legend>
            <tbody id='iHuOC'></tbody>

          <i id='iHuOC'><tr id='iHuOC'><dt id='iHuOC'><q id='iHuOC'><span id='iHuOC'><b id='iHuOC'><form id='iHuOC'><ins id='iHuOC'></ins><ul id='iHuOC'></ul><sub id='iHuOC'></sub></form><legend id='iHuOC'></legend><bdo id='iHuOC'><pre id='iHuOC'><center id='iHuOC'></center></pre></bdo></b><th id='iHuOC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='iHuOC'><tfoot id='iHuOC'></tfoot><dl id='iHuOC'><fieldset id='iHuOC'></fieldset></dl></div>
                • <bdo id='iHuOC'></bdo><ul id='iHuOC'></ul>
                • <small id='iHuOC'></small><noframes id='iHuOC'>

                  本文介紹了Ionic 3 - 使用異步數據更新 Observable的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  對于社交媒體應用程序,我有一組使用 AngularFire 2 由其 ID 引用的提要對象.一旦這些 ID 中的每一個都從存儲實際提要對象的數據庫中提取了相關數據,我希望使用此信息更新 feedCards 可觀察對象,以便我可以異步顯示提要對象的集合.HTML.這是一個相當混亂的事件鏈,所以讓我為你總結一下.

                  <塊引用>

                  循序漸進的方法

                  1. displayFeed()NavController 加載 Main 頁面上的 feed 組件之前調用.
                  2. displayFeed() 獲取 twiner 項,它本質上是一個用戶配置文件項,然后將用戶配置文件存儲在 userProfile 變量中.
                  3. 加載用戶配置文件后,全局 feedCards Observable 將設置為等于 loadFeed(),返回一個 Observable 數組.
                  4. loadFeed() 使用 userProfile 全局對象的 id 值來加載存儲在用戶配置文件中的提要參考列表.
                  5. 然后訂閱此快照并將本地 feed 變量設置為等于提要引用的結果列表.
                  6. loadFeed 返回一個 Observable 對象,其中 feed 引用列表由每個提要引用包含的數據映射.
                  7. pullFeedData(number) 接受對 feed 對象的引用并返回一個帶有相關 feed 數據的 observable.

                  <塊引用>

                  什么有效

                  • alert(JSON.stringify(feedData)); 提醒正確的 feed 對象

                  • 基本上其他的.

                  <塊引用>

                  什么不起作用

                  • feed.map(... 不會更新 feed 數組,因為 pullFeedData(number) 會異步拉取并返回 feedData.因此, alert(JSON.stringify(data)); in displayFeed() 警報 [null].
                  <塊引用>

                  代碼

                  feed.ts

                   userProfile:any;提要:FirebaseListObservable<any>;feedData: FirebaseObjectObservable<any>;feedCards:可觀察的<any[]>;構造函數(公共數據庫:AngularFireDatabase,公共 nativeStorage:NativeStorage){}displayFeed():無效{this.nativeStorage.getItem('twiner').then((res) => {this.userProfile = res;this.feedCards = this.loadFeed();this.feedCards.subscribe((數據)=>{警報(JSON.stringify(數據));})});}loadFeed():Observable<any[]>{變種飼料;this.feed = this.db.list('/twiners/' + this.userProfile.id + '/feed', { preserveSnapshot: true });this.feed.subscribe((snapshots)=>{feed = snapshots});返回 Observable.of(feed.map((snapshot) => {this.pullFeedData(snapshot.val()).subscribe((feedData)=>{警報(JSON.stringify(feedData));返回飼料數據;});})).延遲(1000);}pullFeedData(麻線:數字):任何{return this.db.object('/twines/' + twine, { preserveSnapshot: true });}

                  feed.html

                  <塊引用>

                  總結

                  feed.map 不會用 feed 對象更新 feed,因為新數據是異步提取的.我需要解決這個問題.

                  謝謝!

                  解決方案

                  訂閱的 observable 沒有返回值.它返回一個 Subscription 對象,您可以稍后使用它來取消訂閱.

                  您可以在調用過程中使用 switchMap 從第一個 observable 切換到下一個 observable 并返回值.你也可以使用 forkJoin 來調用一個 observables 數組并等到值數組在訂閱中返回.首先將 feed 類變量聲明為 Observable.

                  feed: Observable<any>;

                  然后在你的 loadFeed():Observable<any[]>

                  return this.feed.switchMap((snapshots) => {讓 observableArray = [];快照.forEach(快照 =>{observableArray.push(this.pullFeedData(snapshot.val()));});返回 Observable.forkJoin(observableArray)})

                  For a social media app, I have a collection of feed objects referenced by their IDs using AngularFire 2. Once each of these IDs has its relevant data pulled from the database that stores the actual feed objects, I wish to update the feedCards Observable object with this information so I can asynchronously display a collection of feed objects in my HTML. It's a pretty confusing chain of events, so let me summarize it for you.

                  Step-by-step Approach

                  1. displayFeed() is invoked right before the NavController loads the feed component on the Main page.
                  2. displayFeed() gets the twiner item, which is essentially a user profile item, and then stores the user profile in the userProfile variable.
                  3. Once the user profile is loaded, the global feedCards Observable is set equal to loadFeed(), which returns an Observable array.
                  4. loadFeed() uses the id value of the userProfile global object to load the list of feed references stored in the user profile.
                  5. This snapshot is then subscribed to and the local feed variable is set equal to the result list of feed references.
                  6. loadFeed returns an Observable object in which the feed reference list is mapped by the data each feed reference contains.
                  7. pullFeedData(number) takes in a reference to a feed object and returns an observable with the associated feed data.

                  What Works

                  • alert(JSON.stringify(feedData)); alerts the correct feed object

                  • Basically everything else.

                  What Doesn't Work

                  • feed.map(... does not update the feed array because pullFeedData(number) pulls and returns the feedData asynchronously. Thus, alert(JSON.stringify(data)); in displayFeed() alerts [null].

                  Code

                  feed.ts

                     userProfile:any;
                     feed: FirebaseListObservable<any>;
                     feedData: FirebaseObjectObservable<any>;
                  
                     feedCards: Observable<any[]>;
                  
                     constructor(public db: AngularFireDatabase, public nativeStorage: NativeStorage) {}
                  
                     displayFeed():void {
                          this.nativeStorage.getItem('twiner').then((res) => {
                                this.userProfile = res;
                                this.feedCards = this.loadFeed();
                                this.feedCards.subscribe((data)=>{
                                      alert(JSON.stringify(data));
                                })
                          });
                    }
                  
                    loadFeed():Observable<any[]> {
                          var feed;
                          this.feed = this.db.list('/twiners/' + this.userProfile.id + '/feed', { preserveSnapshot: true });
                          this.feed.subscribe((snapshots)=>{feed = snapshots});
                          return Observable.of(feed.map((snapshot) => {
                                this.pullFeedData(snapshot.val()).subscribe((feedData)=>{
                                      alert(JSON.stringify(feedData));
                                      return feedData;
                                });
                          })).delay(1000);
                    }
                  
                    pullFeedData(twine:number):any {
                          return this.db.object('/twines/' + twine, { preserveSnapshot: true });
                    }
                  

                  feed.html

                  <ion-content fullscreen scroll="true" overflow-scroll="true">
                        <ion-card *ngIf="feedCards | async">feedCards exist</ion-card>
                        <twine-feed-card *ngFor="let feedCard of feedCards | async"
                              [data]="feedCard"
                        ></twine-feed-card>
                  </ion-content>
                  

                  Summary

                  feed.map does not update feed with feed objects because the new data is being pulled asynchronously. I need a fix for this.

                  Thank you!

                  解決方案

                  A subscribed observable does not return a value. It returns a Subscription object which you can use to unsubscribe later.

                  You can use switchMap to switch from first observable to the next during the call and return the values. Also you can use forkJoin which will call an array of observables and wait till the array of values is returned in subscription. First declare feed class variable as an Observable.

                  feed: Observable<any>;
                  

                  Then in your loadFeed():Observable<any[]>

                  return this.feed.switchMap((snapshots) => {
                               let observableArray = [];
                               snapshots.forEach(snapshot =>{
                                   observableArray.push(this.pullFeedData(snapshot.val()));
                               });
                               return Observable.forkJoin(observableArray)
                          })
                  

                  這篇關于Ionic 3 - 使用異步數據更新 Observable的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Use IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
                  anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 項目中不起作用)
                  Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
                  In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何創建使用 Ionic 組件的自定義指令?)
                  Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動態元素 - Angular 2 amp;離子2)
                  How to reload the ion-page after pop() in ionic2(如何在 ionic2 中的 pop() 之后重新加載離子頁面)

                    <small id='hoO1J'></small><noframes id='hoO1J'>

                    <legend id='hoO1J'><style id='hoO1J'><dir id='hoO1J'><q id='hoO1J'></q></dir></style></legend>
                      <tbody id='hoO1J'></tbody>
                            <bdo id='hoO1J'></bdo><ul id='hoO1J'></ul>
                            <i id='hoO1J'><tr id='hoO1J'><dt id='hoO1J'><q id='hoO1J'><span id='hoO1J'><b id='hoO1J'><form id='hoO1J'><ins id='hoO1J'></ins><ul id='hoO1J'></ul><sub id='hoO1J'></sub></form><legend id='hoO1J'></legend><bdo id='hoO1J'><pre id='hoO1J'><center id='hoO1J'></center></pre></bdo></b><th id='hoO1J'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='hoO1J'><tfoot id='hoO1J'></tfoot><dl id='hoO1J'><fieldset id='hoO1J'></fieldset></dl></div>
                          • <tfoot id='hoO1J'></tfoot>
                            主站蜘蛛池模板: 久久免费国产视频 | 成人av网站在线观看 | 人人超碰在线 | 国产超碰在线观看 | 亚洲国产成人在线 | 黄色片免费在线观看 | www在线播放| 91精品国产成人www | 一区二区三区四区在线视频 | 动漫av在线| 黄色成人小视频 | av免费观看网站 | 一级做a爱片性色毛片 | 日韩毛片网 | 日韩一区二区在线视频 | 日本黄a三级三级三级 | 国产又粗又猛又黄又爽无遮挡 | 97av在线视频 | 欧美亚洲天堂 | 天天操天天操天天操 | 久久精品在线观看 | 国产精品一区在线播放 | 亚洲区一区二 | 久插视频 | 国产一区精品视频 | 成人在线观看免费爱爱 | 中文字幕伊人 | 精品国产乱码久久久久久蜜臀网站 | 日本一区二区高清 | 欧美手机在线 | av入口| www.日本在线观看 | 在线观看免费av网站 | 国产欧美精品一区二区色综合 | 久久er99热精品一区二区 | 91女人18毛片水多国产 | 高清一级片| 亚洲国产激情 | 欧美又大又硬又粗bbbbb | 青草国产 | 中文在线视频 |