pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <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="aa2euqk" 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="0ykyyga" 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="uu2iwgy" id='hoO1J'><tfoot id='hoO1J'></tfoot><dl id='hoO1J'><fieldset id='hoO1J'></fieldset></dl></div>
                          • <tfoot id='hoO1J'></tfoot>
                            主站蜘蛛池模板: 自动记录数据电子台秤,记忆储存重量电子桌称,设定时间记录电子秤-昆山巨天 | 打包钢带,铁皮打包带,烤蓝打包带-高密市金和金属制品厂 | 水平垂直燃烧试验仪-灼热丝试验仪-漏电起痕试验仪-针焰试验仪-塑料材料燃烧检测设备-IP防水试验机 | 南京试剂|化学试剂|分析试剂|实验试剂|cas号查询-专业60年试剂销售企业 | 蓝牙音频分析仪-多功能-四通道-八通道音频分析仪-东莞市奥普新音频技术有限公司 | 铝镁锰板厂家_进口钛锌板_铝镁锰波浪板_铝镁锰墙面板_铝镁锰屋面-杭州军晟金属建筑材料 | 隔离变压器-伺服变压器--输入输出电抗器-深圳市德而沃电气有限公司 | 国际船舶网 - 船厂、船舶、造船、船舶设备、航运及海洋工程等相关行业综合信息平台 | BAUER减速机|ROSSI-MERSEN熔断器-APTECH调压阀-上海爱泽工业设备有限公司 | PCB设计,PCB抄板,电路板打样,PCBA加工-深圳市宏力捷电子有限公司 | 无线讲解器-导游讲解器-自助讲解器-分区讲解系统 品牌生产厂家[鹰米讲解-合肥市徽马信息科技有限公司] | 千斤顶,液压千斤顶-力良企业,专业的液压千斤顶制造商,shliliang.com | 沥青灌缝机_路面灌缝机_道路灌缝机_沥青灌缝机厂家_济宁萨奥机械有限公司 | 利浦顿蒸汽发生器厂家-电蒸汽发生器/燃气蒸汽发生器_湖北利浦顿热能科技有限公司官网 | 世界箱包品牌十大排名,女包小众轻奢品牌推荐200元左右,男包十大奢侈品牌排行榜双肩,学生拉杆箱什么品牌好质量好 - Gouwu3.com | 胶水,胶粘剂,AB胶,环氧胶,UV胶水,高温胶,快干胶,密封胶,结构胶,电子胶,厌氧胶,高温胶水,电子胶水-东莞聚力-聚厉胶粘 | 光泽度计_测量显微镜_苏州压力仪_苏州扭力板手维修-苏州日升精密仪器有限公司 | 棕刚玉_白刚玉_铝酸钙-锐石新材料 | 广州活动策划公司-15+年专业大型公关活动策划执行管理经验-睿阳广告 | 船用烟火信号弹-CCS防汛救生圈-船用救生抛绳器(海威救生设备) | 高低温试验房-深圳高低温湿热箱-小型高低温冲击试验箱-爱佩试验设备 | 欧美日韩国产一区二区三区不_久久久久国产精品无码不卡_亚洲欧洲美洲无码精品AV_精品一区美女视频_日韩黄色性爱一级视频_日本五十路人妻斩_国产99视频免费精品是看4_亚洲中文字幕无码一二三四区_国产小萍萍挤奶喷奶水_亚洲另类精品无码在线一区 | 恒温恒湿试验箱_高低温试验箱_恒温恒湿箱-东莞市高天试验设备有限公司 | 焊管生产线_焊管机组_轧辊模具_焊管设备_焊管设备厂家_石家庄翔昱机械 | 深圳货架厂_仓库货架公司_重型仓储货架_线棒货架批发-深圳市诺普泰仓储设备有限公司 | 会议会展活动拍摄_年会庆典演出跟拍_摄影摄像直播-艾木传媒 | 湖州织里童装_女童男童中大童装_款式多尺码全_织里儿童网【官网】-嘉兴嘉乐网络科技有限公司 | DWS物流设备_扫码称重量方一体机_快递包裹分拣机_广东高臻智能装备有限公司 | 酒店厨房设计_中央厨房设计_北京商用厨房设计公司-奇能商厨 | 骨龄仪_骨龄检测仪_儿童骨龄测试仪_品牌生产厂家【品源医疗】 | 贝壳粉涂料-内墙腻子-外墙腻子-山东巨野七彩贝壳漆业中心 | 环氧铁红防锈漆_环氧漆_无溶剂环氧涂料_环氧防腐漆-华川涂料 | 金属波纹补偿器厂家_不锈钢膨胀节价格_非金属伸缩节定制-庆达补偿器 | 【甲方装饰】合肥工装公司-合肥装修设计公司,专业从事安徽办公室、店面、售楼部、餐饮店、厂房装修设计服务 | 隔爆型防爆端子分线箱_防爆空气开关箱|依客思 | 快速门厂家批发_PVC快速卷帘门_高速门_高速卷帘门-广州万盛门业 快干水泥|桥梁伸缩缝止水胶|伸缩缝装置生产厂家-广东广航交通科技有限公司 | 帽子厂家_帽子工厂_帽子定做_义乌帽厂_帽厂_制帽厂 | 滤芯,过滤器,滤油机,贺德克滤芯,精密滤芯_新乡市宇清流体净化技术有限公司 | 细砂提取机,隔膜板框泥浆污泥压滤机,螺旋洗砂机设备,轮式洗砂机械,机制砂,圆锥颚式反击式破碎机,振动筛,滚筒筛,喂料机- 上海重睿环保设备有限公司 | 袋式过滤器,自清洗过滤器,保安过滤器,篮式过滤器,气体过滤器,全自动过滤器,反冲洗过滤器,管道过滤器,无锡驰业环保科技有限公司 | 合肥废气治理设备_安徽除尘设备_工业废气处理设备厂家-盈凯环保 合肥防火门窗/隔断_合肥防火卷帘门厂家_安徽耐火窗_良万消防设备有限公司 |