小编uci*_*ska的帖子

如何在 Firebase 中按子值排序

我有这样的数据:

    scores: {
      uid1: {
        score: 15,
        displayName: "Uciska"
      },
      uid2: {
        score: 3,
        displayName: "Bob"
      },
      uid3: {
        etc...
      }
    }
Run Code Online (Sandbox Code Playgroud)

我想按分数对它们进行排名,只保留前 100 名。

我是按照文档做到的。但它不起作用。即使分数发生变化,它也始终返回相同的顺序。

    const query = firebase.database().ref('scores')
      .orderByChild('score')
      .limitToLast(100)

      query.on('child_added', snapshot => {
        const score = snapshot.val().score
        console.log(score)
    })
Run Code Online (Sandbox Code Playgroud)

我也在优化规则中添加了这一点,但我不确定它是否正确:

    "scores": {
      ".indexOn": ["score"]
    }
Run Code Online (Sandbox Code Playgroud)

正确的方法是什么?

firebase firebase-realtime-database

3
推荐指数
1
解决办法
8341
查看次数

添加Snipcart到盖茨比

我正在尝试将Snipcart整合到Gatsby(第2版)中.

html.js像这样编辑文件:

import React from "react"
import PropTypes from "prop-types"

export default class HTML extends React.Component {
  render() {
    return (
      <html {...this.props.htmlAttributes}>
        <head>
          <meta charSet="utf-8" />
          <meta httpEquiv="x-ua-compatible" content="ie=edge" />
          <meta
            name="viewport"
            content="width=device-width, initial-scale=1, shrink-to-fit=no"
          />
          {this.props.headComponents}

          {/* Snipcart */}
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
          <script src="https://cdn.snipcart.com/scripts/2.0/snipcart.js" id="snipcart" data-api-key="UF45pIjZjAtZWJkYS00MGEwLWIxZWEtNjljZThjNTRiNjA4NjM2NDg1MzAzMzQyNfDrr48"></script>
          <link href="https://cdn.snipcart.com/themes/2.0/base/snipcart.min.css" type="text/css" rel="stylesheet" />

        </head>
        <body {...this.props.bodyAttributes}>
          {this.props.preBodyComponents}
          <div
            key={`body`}
            id="___gatsby"
            dangerouslySetInnerHTML={{ __html: this.props.body }}
          />
          {this.props.postBodyComponents}

        </body>
      </html>
    )
  }
}

HTML.propTypes = {
  htmlAttributes: PropTypes.object,
  headComponents: PropTypes.array,
  bodyAttributes: …
Run Code Online (Sandbox Code Playgroud)

reactjs snipcart gatsby

3
推荐指数
1
解决办法
260
查看次数

我无法在 netlify 中访问我的环境变量

我用GatsbyNetlify编写了一个应用程序

我正在通过我的环境变量使用Snipcart公共 API 密钥html.js在 dev 中有测试密钥,在 prod 中有实时密钥)。

import React from 'react'
import PropTypes from 'prop-types'

export default class HTML extends React.Component {
  render() {
    return (
      <html lang='en' {...this.props.htmlAttributes}>
        <head>
          <meta charSet='utf-8' />
          <meta httpEquiv='x-ua-compatible' content='ie=edge' />
          <meta
            name='viewport'
            content='width=device-width, initial-scale=1, shrink-to-fit=no'
          />
          {this.props.headComponents}

          {/* Snipcart */}
          <script
            defer
            src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js'
          />
          <script
            defer
            src='https://cdn.snipcart.com/scripts/2.0/snipcart.js'
            id='snipcart'
            data-api-key={process.env.SNIPCART_API_KEY}
          />
          <link
            href='https://cdn.snipcart.com/themes/2.0/base/snipcart.min.css'
            type='text/css'
            rel='stylesheet'
          />
        </head>
        <body {...this.props.bodyAttributes}>
          {this.props.preBodyComponents}
          <div
            key={'body'} …
Run Code Online (Sandbox Code Playgroud)

gatsby netlify

2
推荐指数
1
解决办法
1944
查看次数