久久久久久久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>
                            主站蜘蛛池模板: 黄色片视频网站 | 欧美成人a| 欧美激情综合 | 国产精品美女久久久久aⅴ国产馆 | a国产视频 | 国产精品一区二区av | 成人精品网 | 国产亚洲精品精品国产亚洲综合 | 精品一区二区三区在线观看国产 | 99亚洲精品 | 精品国产乱码久久久久久88av | 亚洲精品一区二区三区蜜桃久 | 欧美影院 | 日韩福利在线 | 国内精品久久久久久影视8 最新黄色在线观看 | 国产美女一区 | 一区二区三区高清不卡 | 国产农村一级国产农村 | 麻豆视频在线免费看 | 国精产品一区一区三区免费完 | 久久精品视频在线免费观看 | 中文字幕精品视频在线观看 | 国产欧美精品在线 | 国产精品免费观看 | 午夜国产精品视频 | 亚洲一区 | 国产精品高清在线 | 欧美午夜精品 | 日韩欧美在线一区 | 农村真人裸体丰满少妇毛片 | 日韩精品一区二区三区视频播放 | 一区二区三区高清 | 成人午夜精品 | www.日韩欧美 | www.国产精品 | 色综合久久天天综合网 | 国产精品成人久久久久 | 久久噜噜噜精品国产亚洲综合 | 欧美一级二级三级视频 | 久久精品欧美一区二区三区不卡 | av日韩在线播放 |