Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 如何使用angularFire 2为表格分页_Firebase_Firebase Realtime Database_Angularfire2 - Fatal编程技术网

Firebase 如何使用angularFire 2为表格分页

Firebase 如何使用angularFire 2为表格分页,firebase,firebase-realtime-database,angularfire2,Firebase,Firebase Realtime Database,Angularfire2,如何使用timestamp键使用angularFire2为表分页 我有2000种产品,我想根据时间戳显示10种产品,从最新到旧 每次用户单击“下一步”时,我都希望显示从最新到较旧的10个项目 Firebase数据库/产品/产品 { “添加人”:roussi@drop.com", “买入价”:0, “品牌”:“奇科”, “自定义id”:“125790”, “描述”:“婴儿时刻”\n”, “图像名称”:“αρχείλήψης.png”, “图像路径”:“/products/v7F9QZ1Uαρχεί

如何使用timestamp键使用angularFire2为表分页

我有2000种产品,我想根据时间戳显示10种产品,从最新到旧

每次用户单击“下一步”时,我都希望显示从最新到较旧的10个项目

Firebase数据库/产品/产品
{
“添加人”:roussi@drop.com",
“买入价”:0,
“品牌”:“奇科”,
“自定义id”:“125790”,
“描述”:“婴儿时刻”

\n”, “图像名称”:“αρχείλήψης.png”, “图像路径”:“/products/v7F9QZ1Uαρχείολήψης.png”, “售价”:2.52, “创建时间”:“2017年5月18日”, “时间戳”:149778593006, “标题”:“Chicco-婴儿时刻ωρομάντηλα-72τεμ”, “权重”:“0” }
firebase.service.ts
//orderBy='timestamp'
getProducts(订购人){
this.products=this.db.list('/products',{query:{
orderByChild:orderBy,
限时:8
}})如可观察到的;
返回this.products.map((arr)=>{return arr.reverse();});
}
getNextProducts(orderBy、first、last){
让第一把钥匙;
让最后一把钥匙;
让林;
让pNum;
this.products=this.db.list('/products',{query:{
orderByKey:orderBy,
答:最后,
//完:10,,
限时:5
}})如可观察到的;
退回本产品;
//返回this.products.map((arr)=>{return arr.reverse();});
}
产品.组件.ts
/===================================================================//
恩戈尼尼特(){
//设置每页的默认行数
this.rowsPerPage=10;
this.firebaseService.getProducts('timestamp').subscribe(products=>{
这个。产品=产品;
this.itemsShowing=products.length;
log('getNextProducts start');
console.log(this.Products);
this.loadComplete=true;
让第一个元素;
让最后一个元素;
for(设i=0;i{
这个。产品=产品;
让第一个元素;
让最后一个元素;
for(设i=0;i
传递给方法的值是多少
GetNextProducts
?(最后一个的值)。还有一个问题。为什么在
GetNextProducts
中决定使用
OrderByKey
而不是像在
GetProducts
方法中那样使用
OrderByChild
?如angularfire2的文档所述:
orderByKey
Boolean to order by Firebase数据库键。和
orderByChild
指定要按其排序的子级。
{
  "added_by" : "roussi@drop.com",
  "bought_price" : 0,
  "brand" : "Chicco",
  "custom_id" : "125790",
  "description" : "<h3><span style=\"font-size:12px\"><strong>Baby Moment</span></p>\n",
  "image_name" : "αρχείο λήψης.png",
  "image_path" : "/products/v7F9QZ1Uαρχείο λήψης.png",
  "sell_price" : 2.52,
  "time_created" : "18/5/2017",
  "timestamp" : 1497785930206,
  "title" : "Chicco - Baby Moments Μωρομάντηλα - 72τεμ.",
  "weight" : "0"
}
  // orderBy = 'timestamp'

  getProducts(orderBy) {
    this.products = this.db.list('/products', { query: {
      orderByChild: orderBy,
      limitToLast: 8
    }}) as FirebaseListObservable<Product[]>;

    return this.products.map( (arr) => { return arr.reverse(); } );
  }

  getNextProducts(orderBy, first, last) {

    let firstKey;
    let lastKey;
    let lim;
    let pNum;


    this.products = this.db.list('/products', { query: {
      orderByKey: orderBy,
      startAt: last,
      // endAt: 10,
      limitToLast: 5
    }}) as FirebaseListObservable<Product[]>;

    return this.products;
    // return this.products.map( (arr) => { return arr.reverse(); } );
  }
   // =============== ON INIT ================ //
  ngOnInit() {

    // set the default rows per page
    this.rowsPerPage = 10;

    this.firebaseService.getProducts('timestamp').subscribe(products => {

      this.Products = products;
      this.itemsShowing = products.length;

      console.log('getNextProducts start');
      console.log(this.Products);
      this.loadComplete = true;

      let firstElement;
      let lastElement;

      for (let i = 0; i < products.length; i++) {
        firstElement = products[0];
        lastElement  = products[i];

      }


      console.log('first element ' + firstElement.title);
      console.log('last element '  + lastElement.title);

      this.firstKey = firstElement.timestamp;
      this.lastKey  = lastElement.timestamp;


    });
}




  // =============== NEXT BUTTON ================ //
  next () {

    this.firebaseService.getNextProducts('timestamp', this.firstKey, this.lastKey).subscribe(products => {

      this.Products = products;

      let firstElement;
      let lastElement;

      for (let i = 0; i < products.length; i++) {
        firstElement = products[0];
        lastElement  = products[i];

      }

      console.log('first element ' + firstElement.title);
      console.log('last element '  + lastElement.title);

      this.firstKey = firstElement.timestamp;
      this.lastKey  = lastElement.timestamp;


      console.log('getNextProducts start');

    });

 }