firebase-如何使用rxjs划为拼写 - 最后的和平

发布于 2025-01-24 04:43:09 字数 1828 浏览 0 评论 0原文

我看到了这篇文章: Cloud Firestore-如何使用RXJS

这正是我需要的,但我不明白如何重现

import { UsersService } from '../../../shared/services/users.service';

我只需要理解此服务中的内容,因为我不能像getUsers()loadMoredata()。我正在学习有关AngularFire的新模块化方法,上面的答案是我需要理解的方法才能正确实施分页。

到目前为止,我所做的事情:

import {
  collection,
  collectionData,
  Firestore,
  limit,
  orderBy,
  query,
  startAfter
} from "@angular/fire/firestore";


querySnapshot:any;
lastInResponse:any;


  constructor( private stringEmitted: StringBridgeService, private firestore: Firestore ) {
  }

  ngOnInit(): void {
    this.stringEmitted.stringChanged(this.actualTitle);
    this.loadCustomers('customers', 'name', 5)
  }


  loadCustomers(collectionName:string, order:string, max:number) {
    return collectionData(query(collection(this.firestore, collectionName), orderBy(order), limit(max))).subscribe(
      response => {
        // @ts-ignore
        this.lastInResponse = response[response.length - 1];
        this.querySnapshot = response;
      }
    );
  }

  loadMore(data:object) {
    return collectionData(query(collection(this.firestore, 'customers'), orderBy('name'), limit(5), startAfter(data))).subscribe(
      response => {
        // @ts-ignore
        this.lastInResponse = response[response.length - 1];
        this.querySnapshot = this.querySnapshot.concat(response);
      }
    );
  }

  myTest() {
    console.log(this.lastInResponse);
  }

我只有这个代码错误firbaseError:function startafter()带有无效数据的函数。函数myTest()将从最后一个客户写入控制台的正确数据,但仍然出现错误。

正确的数据类型是什么?我该如何转换?

任何帮助将不胜感激!谢谢!

I saw this post: Cloud Firestore - How to paginate data with RXJS

This is exactly what I need but I don't understand how to reproduce the

import { UsersService } from '../../../shared/services/users.service';

I just need to understand what is inside this service because I can't make a function work like both getUsers() and loadMoreData(). I'm learning the new MODULAR approach on AngularFire and the answer above is the one I need to understand to properly implement pagination.

What I had done so far:

import {
  collection,
  collectionData,
  Firestore,
  limit,
  orderBy,
  query,
  startAfter
} from "@angular/fire/firestore";


querySnapshot:any;
lastInResponse:any;


  constructor( private stringEmitted: StringBridgeService, private firestore: Firestore ) {
  }

  ngOnInit(): void {
    this.stringEmitted.stringChanged(this.actualTitle);
    this.loadCustomers('customers', 'name', 5)
  }


  loadCustomers(collectionName:string, order:string, max:number) {
    return collectionData(query(collection(this.firestore, collectionName), orderBy(order), limit(max))).subscribe(
      response => {
        // @ts-ignore
        this.lastInResponse = response[response.length - 1];
        this.querySnapshot = response;
      }
    );
  }

  loadMore(data:object) {
    return collectionData(query(collection(this.firestore, 'customers'), orderBy('name'), limit(5), startAfter(data))).subscribe(
      response => {
        // @ts-ignore
        this.lastInResponse = response[response.length - 1];
        this.querySnapshot = this.querySnapshot.concat(response);
      }
    );
  }

  myTest() {
    console.log(this.lastInResponse);
  }

I only have ONE problem with this code ERROR FirebaseError: Function startAfter() called with invalid data. The function myTest() writes the correct data from the last customer to the console but still the error appears.

What is the right type of data? How could I convert?

Any help will be greatly appreciated! Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半枫 2025-01-31 04:43:09

我设法找到了解决方案!

import {
  collection,
  collectionData,
  Firestore,
  limit,
  orderBy,
  query,
  startAfter
} from "@angular/fire/firestore";


querySnapshot:any;
lastInResponse:any;


  constructor( private stringEmitted: StringBridgeService, private firestore: Firestore ) {
  }

  ngOnInit(): void {
    this.stringEmitted.stringChanged(this.actualTitle);
    this.loadCustomers('customers', 'name', 5)
  }


  loadCustomers(collectionName:string, order:string, max:number) {
    return collectionData(query(collection(this.firestore, collectionName), orderBy(order), limit(max))).subscribe(
      response => {
        this.lastInResponse = response[response.length - 1];
        this.querySnapshot = response;
      }
    );
  }

  loadMore(data:any) {
    if(this.lastInResponse){
      return collectionData(query(collection(this.firestore, 'customers'), orderBy('name'), limit(3), startAfter(data['name']))).subscribe(
        response => {
          this.lastInResponse = response[response.length - 1];
          this.querySnapshot = this.querySnapshot.concat(response);
          // this.querySnapshot = response;
        }
      );
    }
    return null
  }

  myTest() {
    console.log(this.lastInResponse);
  }

startafter()在我的情况下,我的列表上的姓氏要求。此处使用了True 模块化方法。

谢谢大家!

I managed to find the solution!

import {
  collection,
  collectionData,
  Firestore,
  limit,
  orderBy,
  query,
  startAfter
} from "@angular/fire/firestore";


querySnapshot:any;
lastInResponse:any;


  constructor( private stringEmitted: StringBridgeService, private firestore: Firestore ) {
  }

  ngOnInit(): void {
    this.stringEmitted.stringChanged(this.actualTitle);
    this.loadCustomers('customers', 'name', 5)
  }


  loadCustomers(collectionName:string, order:string, max:number) {
    return collectionData(query(collection(this.firestore, collectionName), orderBy(order), limit(max))).subscribe(
      response => {
        this.lastInResponse = response[response.length - 1];
        this.querySnapshot = response;
      }
    );
  }

  loadMore(data:any) {
    if(this.lastInResponse){
      return collectionData(query(collection(this.firestore, 'customers'), orderBy('name'), limit(3), startAfter(data['name']))).subscribe(
        response => {
          this.lastInResponse = response[response.length - 1];
          this.querySnapshot = this.querySnapshot.concat(response);
          // this.querySnapshot = response;
        }
      );
    }
    return null
  }

  myTest() {
    console.log(this.lastInResponse);
  }

startAfter() requires, in my case, the last name on my list. The true modular approach was used here.

Thank you all!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文