【问题标题】:Is there a way to send one data package from multiple input fields as 1 package to Firebase?有没有办法将一个数据包从多个输入字段作为 1 个包发送到 Firebase?
【发布时间】:2019-11-07 05:23:38
【问题描述】:

我正在将 Unity(用 C# 编码)制作的移动应用上的 3 个输入字段的信息发送到 Firebase 数据库,但正如您所见,它似乎是单独发送每个输入字段的数据,然后将其堆叠在一起.See attached 理想情况下,我只想要最后一组完整信息。

using System.Collections;
using System.Collections.Generic;
using Proyecto26;
using UnityEngine;
using UnityEngine.UI;

public class PlayerScores : MonoBehaviour
{
    public InputField dateText;
    public InputField classText;
    public InputField informationText;

    User user = new User();

    public static string Information;
    public static string Class;
    public static string Date;

    // Start is called before the first frame update
    private void Start()
    {

    }

    public void OnSubmit()
    {
        Date = dateText.text;
        PostToDatabase();

        {
            Class = classText.text;
            PostToDatabase();
        }

        {
            Information = informationText.text;
            PostToDatabase();
        }
    }

    public void OnGetScore()
    {
        RetrieveFromDatabase();

    }

    private void PostToDatabase()
    {
        User user = new User();
        RestClient.Put("https://anti-bullying-demo.firebaseio.com/" + Date + Class + Information + ".json", user);
    }

    private void RetrieveFromDatabase()
    {
        RestClient.Get<User>("https://anti-bullying-demo.firebaseio.com/" + Date + Class + Information + ".json").Then(response =>
        {
            user = response;
        });
    }
}

【问题讨论】:

    标签: c# firebase unity3d firebase-realtime-database


    【解决方案1】:

    在您的OnSubmit() 函数调用中,您调用了三次PostToDatabase() - 最后只需要调用一次。

    public void OnSubmit()
    {
        Date = dateText.text;
    
        {
            Class = classText.text;
        }
    
        {
            Information = informationText.text;
        }
    
        PostToDatabase();
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2015-12-18
      • 1970-01-01
      • 2012-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多