Javascript 使用ionic 5将数据从firebase存储到firebase脱机存储中
我是爱奥尼亚的新手,有棱角和火基。所以我想将我的firebase数据列表存储在缓存中,这样页面就可以加载一次,因为目前我有很多数据,当用户每次进入页面时,它会减慢应用程序的速度。请问我该如何处理我的问题 那是我的模型Javascript 使用ionic 5将数据从firebase存储到firebase脱机存储中,javascript,angular,firebase,ionic-framework,google-cloud-firestore,Javascript,Angular,Firebase,Ionic Framework,Google Cloud Firestore,我是爱奥尼亚的新手,有棱角和火基。所以我想将我的firebase数据列表存储在缓存中,这样页面就可以加载一次,因为目前我有很多数据,当用户每次进入页面时,它会减慢应用程序的速度。请问我该如何处理我的问题 那是我的模型 import { Media } from './Media'; export class Post { id?: string; icone: string; owner?: string; titr
import { Media } from './Media';
export class Post {
id?: string;
icone: string;
owner?: string;
titre?: string;
description?: string;
medias?: Array<Media> = new Array();
mediasThumbnail?: Array<Media> = new Array();
abonnees?: Array<string> = new Array();
typePost?: string; // Formation, Projet, ...
refSrc?: string;
date?;
location?: string;
userSaved: string[] = new Array();
userDel: string[] = new Array();
debut;
fin;
breComment: number;enter code here
descriptioncourte: string;
competences?: string[];
userliked?: string[] = new Array();
userviewed?: string[] = new Array();
}
这就是我列出数据的方式
class MyPage {
constructor(private postSvc: PostService) {
this.postSvc.
findByfilters(this.keys,
this.operator,
this.values).onSnapshot((data) => {
this.postitems = new Array<Post>();
data.forEach(async (item) => {
const post = item.data() as Post;
post.id = item.id;
this.postitems.push(post);
})
});
}
}
classmypage{
构造函数(专用postSvc:PostService){
这是postSvc。
findByfilters(此.keys,
这是我的接线员,
此.values).onSnapshot((数据)=>{
this.positems=新数组();
data.forEach(异步(项)=>{
const post=item.data()作为post;
post.id=item.id;
此.positems.push(post);
})
});
}
}
有人能帮我演示一下如何实现我的服务,以便在firebase脱机保存数据吗?
谢谢。AngularFire提供了一个。这对您来说是完全透明的,db.collection()
将只返回AngularFire在没有可用连接时存储在其缓存中的内容
要启用它,您只需在模块中添加AngularFirestoreModule.enablePersistence()
(可能是app.module.ts
)
从'@angular/platform browser'导入{BrowserModule};
从“@angular/core”导入{NgModule};
从“./app.component”导入{AppComponent};
从'@angular/fire'导入{AngularFireModule};
从'@angular/fire/firestore'导入{AngularFirestoreModule};
从'@angular/fire/auth'导入{angularfireauthmodel};
从“../environments/environment”导入{environment};
@NGD模块({
进口:[
浏览器模块,
AngularFireModule.initializeApp(environment.firebase),
AngularFirestoreModule.enablePersistence()//
class MyPage {
constructor(private postSvc: PostService) {
this.postSvc.
findByfilters(this.keys,
this.operator,
this.values).onSnapshot((data) => {
this.postitems = new Array<Post>();
data.forEach(async (item) => {
const post = item.data() as Post;
post.id = item.id;
this.postitems.push(post);
})
});
}
}