使用navParams的Angularfire2查询不起作用

时间:2017-11-11 16:46:11

标签: firebase firebase-realtime-database ionic3 angularfire2

我想使用console.log(this.navParams.get('id')) // prints 10 const id = this.navParams.get('id'); this.categoryRef = this.db.list('/category', ref => ref.orderByChild('id').equalTo(id)); this.category = this.categoryRef.snapshotChanges().map(changes => { return changes.map(c => ({ key: c.payload.key, ...c.payload.val() })); }); 获取一些数据,但它不起作用,但如果我提供静态值,那么它的工作。我不知道出了什么问题。这是我的代码不起作用并返回空

const id = 10;
this.categoryRef = this.db.list('/category', ref => ref.orderByChild('id').equalTo(id));
this.category = this.categoryRef.snapshotChanges().map(changes => {
    return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});

如果我给出静态值,那么它就像

一样
var store = new Vuex.Store({
  state: {
    id: 1,
    name: 'aaa',
    last: 'bbb'
  },
  mutations: {
    change (state, payload) {
      state = Object.assign(state, payload)
    }
  }
})

new Vue({
  el: '#app',
  store,
  created () {
    setTimeout(_ => {
      this.$store.commit('change', {
        id: 2,
        last: 'ccc'
      })
    }, 2000)
    setTimeout(_ => {
      this.$store.commit('change', {
        name: 'ddd'
      })
    }, 4000)
  }
})

2 个答案:

答案 0 :(得分:0)

你能尝试下面的吗?

#include <iostream>


//singly linked list using struct node


void add(struct node *);


struct node {
    int data;
    struct node *next;
};



int main()
{
    struct node *head;
    struct node *conductor;

    struct node a;

    *head = a;
    *conductor = a;

    add( conductor);
}

void add(struct node *conductor)
{
    conductor->next = NULL;

    std::cout << "What is the data?\n";

    int x;

    std::cin>> x ;

    if (x == -1) {
        return;
    } else {
        conductor->data  = x;

        conductor->next = new struct node;

        conductor = conductor->next;

        add(conductor);

        return;
    }
}

答案 1 :(得分:0)

实际上我在firebase数据库端发现了一个问题。我的ID没有存储为双引号,例如"1"它保存为1然后我将其设为双引号,它工作正常 enter image description here