【问题标题】:Accessing boolean in Firebase在 Firebase 中访问布尔值
【发布时间】:2020-09-11 01:06:03
【问题描述】:

我正在使用 Firebase 开发 NativeScript 应用程序。 我必须根据它们在 firebase 数组对象中的状态来显示特色元素。状态是

featured= true.

我想使用查询参数直接在我的函数的 url 中进行过滤(即在 http 请求中不使用标头)。

这是 firebase 数据结构的示例

dishes
    0
        category: 
        "mains"
        comments
        description: 
        "A unique combination of Indian Uthappam (pancak..."
        featured: "true"
        id: 0
        image:  "https://www.inspiredtaste.net/wp-content/upload..."
        label: "Hot"
        name:  "Uthappizza"
        price:  "4.99"

这是我的基于 typscript 角度的方法:

 getFeaturedDish(): Observable<Dish> {
    return this.http.get<Dish[]>(baseURL + 'dishes.json' /**query placeholder */).pipe(map(dishes => dishes[0]))
      .pipe(catchError(this.processHTTPMsgService.handleError));
  }

【问题讨论】:

    标签: javascript json angular firebase-realtime-database


    【解决方案1】:

    要过滤featured"true" 的结构,您可以使用:

    dishes.json?orderBy="featured"&equalTo="true"
    

    不要忘记 "true" 周围的双引号,因为您存储的是字符串值,而不是布尔值。

    另请参阅 filtering data with the REST API 上的 Firebase 文档。

    【讨论】:

    • 我访问了firebase的网站,效果很好。非常感谢弗兰克!高度赞赏。我现在正在为动态 id 加载而苦苦挣扎。如果您能提出一些见解,那就太好了。在我的 firebase 中,这是对象 [name]firebaseio.com/disses/3 的地址。这是我的方法 getDish(id: number): Observable { return this.http.get(baseURL +'dishes.json/' + /** id of my object on click*/) .pipe (catchError(this.processHTTPMsgService.handleError)); }.
    • 我对 Firebase 完全陌生。如果您能发表评论,我会很高兴。PS:对象的 id 是通过 nativescript 路由获取的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 2016-01-18
    • 2010-12-24
    相关资源
    最近更新 更多