使用“userData.uid”作为键

时间:2016-01-08 18:20:20

标签: firebase

firebase就像一位毫不留情的母亲一样击败我。 看看我的代码:

public class DownloadCsvActionResult : ActionResult
{
    public ReportBase Report { get; set; }
    public string fileName { get; set; }

    private string ReportData { get; set; }

    public DownloadCsvActionResult(ReportBase report, string pFileName)
    {
        Report = report;
        fileName = pFileName;
        ReportData = RenderReport();
    }

    private string RenderReport()
    {
        var reportBody = new StringBuilder();

        reportBody.AppendLine(Report.ReportName);
        reportBody.Append(Environment.NewLine + Environment.NewLine);

        foreach (var thisSection in Report.ReportSections)
        {
            reportBody.Append(thisSection.ReportSectionName + Environment.NewLine);

            if (thisSection.ReportItems != null)
            {
                var itemType = thisSection.ReportItems.GetType().GetGenericArguments().Single();

                var first = true;
                foreach (var prop in itemType.GetProperties())
                {
                    if (!first) reportBody.Append(",");

                    DisplayAttribute attribute = prop.GetCustomAttributes(typeof(DisplayAttribute), false)
                         .Cast<DisplayAttribute>()
                         .SingleOrDefault();

                    string displayName = (attribute != null) ? attribute.Name : prop.Name;
                    reportBody.Append(displayName);

                    first = false;
                }
                reportBody.Append(Environment.NewLine);

                foreach (var thisItem in thisSection.ReportItems)
                {
                    var firstData = true;
                    foreach (var prop in itemType.GetProperties())
                    {
                        if (!firstData) reportBody.Append(",");
                        reportBody.Append(prop.GetValue(thisItem,null));
                        firstData = false;
                    }
                    reportBody.Append(Environment.NewLine);
                }
            }

            reportBody.Append(Environment.NewLine);
        }

        return reportBody.ToString();
    }

    public override void ExecuteResult(ControllerContext context)
    {
        //Create a response stream to create and write the Excel file
        HttpContext curContext = HttpContext.Current;
        curContext.Response.Clear();
        curContext.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
        curContext.Response.Charset = "";
        curContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        curContext.Response.ContentType = "application/vnd.ms-excel";

        //Write the stream back to the response
        curContext.Response.Write(ReportData);
        curContext.Response.End();

    }
}

一切正常,没有错误,但看看我的json: *

ref.createUser({
            email    : $("#email").val(),
            password : $("#senha").val()
        }, function(error, userData) {
            if (error) {
              alert("Nao foi possivel cadastrar: "+error);
            } else {
                ref.child("fornecedores").push({
                    [userData.uid]:{
                        email: $("#email").val(),
                        logo: nome+".jpg",
                        nome: $("#nome").val()
                    }
                },function(error) {
                    if (error) {
                      alert("Nao foi possivel salvar: " + error);
                    } else {
                        alert("Seus dados foram salvos!: "+userData.uid);
                    }
                });
            }
    });

*

为什么有两个键?这个“-K7X ......”来自???

2 个答案:

答案 0 :(得分:1)

push()自动生成节点的密钥,然后userData.uid是带有电子邮件,徽标和nome的孩子。

来自Firebase Saving Data

  

每次调用push()时,您的数据库都会生成一个唯一的ID,例如

messages/users/<unique-user-id>/<username>

答案 1 :(得分:0)

这是杰伊说的,谢谢!

ref.createUser({
            email    : $("#email").val(),
            password : $("#senha").val()
        }, function(error, userData) {
            if (error) {
                $("#load").css("display","none");
                alert("Nao foi possivel salvar: "+error);
            } else {
                ref.child("fornecedores").child(userData.uid).set({
                    email: $("#email").val(),
                    logo: nome+".jpg",
                    nome: $("#nome").val()
                },function(error) {
                    $("#load").css("display","none");
                    if (error) {
                      alert("Nao foi possivel salvar: " + error);
                    } else {
                        alert("Seus dados foram salvos!: "+userData.uid);
                    }
                });
            }
    });