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>
                            主站蜘蛛池模板: 辐射色度计-字符亮度测试-反射式膜厚仪-苏州瑞格谱光电科技有限公司 | 智能案卷柜_卷宗柜_钥匙柜_文件流转柜_装备柜_浙江福源智能科技有限公司 | 台湾阳明固态继电器-奥托尼克斯光电传感器-接近开关-温控器-光纤传感器-编码器一级代理商江苏用之宜电气 | 健康管理师报考条件,考试时间,报名入口—首页 | 波纹补偿器_不锈钢波纹补偿器_巩义市润达管道设备制造有限公司 | Trimos测长机_测高仪_TESA_mahr,WYLER水平仪,PWB对刀仪-德瑞华测量技术(苏州)有限公司 | 模具钢_高速钢_不锈钢-万利钢金属材料 | 东莞工厂厂房装修_无尘车间施工_钢结构工程安装-广东集景建筑装饰设计工程有限公司 | 太原装修公司_山西整装家装设计_太原室内装潢软装_肖邦家居 | 培训一点通 - 合肥驾校 - 合肥新亚驾校 - 合肥八一驾校 | SDI车窗夹力测试仪-KEMKRAFT方向盘测试仪-上海爱泽工业设备有限公司 | 广州小程序开发_APP开发公司_分销商城系统定制_小跑科技 | 法兰连接型电磁流量计-蒸汽孔板节流装置流量计-北京凯安达仪器仪表有限公司 | 广东护栏厂家-广州护栏网厂家-广东省安麦斯交通设施有限公司 | 合肥活动房_安徽活动板房_集成打包箱房厂家-安徽玉强钢结构集成房屋有限公司 | 匀胶机旋涂仪-声扫显微镜-工业水浸超声-安赛斯(北京)科技有限公司 | 杭州火蝠电商_京东代运营_拼多多全托管代运营【天猫代运营】 | 超细|超微气流粉碎机|气流磨|气流分级机|粉体改性机|磨粉机|粉碎设备-山东埃尔派粉体科技 | 防渗土工膜|污水处理防渗膜|垃圾填埋场防渗膜-泰安佳路通工程材料有限公司 | Type-c防水母座|贴片母座|耳机接口|Type-c插座-深圳市步步精科技有限公司 | 电动葫芦-河北悍象起重机械有限公司 | 无尘烘箱_洁净烤箱_真空无氧烤箱_半导体烤箱_电子防潮柜-深圳市怡和兴机电 | 安全,主动,被动,柔性,山体滑坡,sns,钢丝绳,边坡,防护网,护栏网,围栏,栏杆,栅栏,厂家 - 护栏网防护网生产厂家 | 防爆电机_防爆电机型号_河南省南洋防爆电机有限公司 | 制氮设备-变压吸附制氮设备-制氧设备-杭州聚贤气体设备制造有限公司 | 波纹补偿器_不锈钢波纹补偿器_巩义市润达管道设备制造有限公司 | 芝麻黑-芝麻黑石材厂家-永峰石业 | 糖衣机,除尘式糖衣机,全自动糖衣机,泰州市长江制药机械有限公司 体感VRAR全息沉浸式3D投影多媒体展厅展会游戏互动-万展互动 | 颚式破碎机,圆锥破碎机,制砂机-新乡市德诚机电制造有限公司 | 水篦子|雨篦子|镀锌格栅雨水篦子|不锈钢排水篦子|地下车库水箅子—安平县云航丝网制品厂 | LED灯杆屏_LED广告机_户外LED广告机_智慧灯杆_智慧路灯-太龙智显科技(深圳)有限公司 | 巨野月嫂-家政公司-巨野县红墙安康母婴护理中心 | SDG吸附剂,SDG酸气吸附剂,干式酸性气体吸收剂生产厂家,超过20年生产使用经验。 - 富莱尔环保设备公司(原名天津市武清县环保设备厂) | 软膜天花_软膜灯箱_首选乐创品牌_一站式天花软膜材料供应商! | 煤机配件厂家_刮板机配件_链轮轴组_河南双志机械设备有限公司 | 艺术涂料_进口艺术涂料_艺术涂料加盟_艺术涂料十大品牌 -英国蒙太奇艺术涂料 | 篷房|仓储篷房|铝合金篷房|体育篷房|篷房厂家-华烨建筑科技官网 知名电动蝶阀,电动球阀,气动蝶阀,气动球阀生产厂家|价格透明-【固菲阀门官网】 | 拉曼光谱仪_便携式|激光|显微共焦拉曼光谱仪-北京卓立汉光仪器有限公司 | 国际高中-国际学校-一站式择校服务-远播国际教育 | 工业废水处理|污水处理厂|废水治理设备工程技术公司-苏州瑞美迪 今日娱乐圈——影视剧集_八卦娱乐_明星八卦_最新娱乐八卦新闻 | 有声小说,听书,听小说资源库-听世界网 |