【问题标题】:How do you update objects in a Parse.com database using Xamarin?如何使用 Xamarin 更新 Parse.com 数据库中的对象?
【发布时间】:2015-10-27 00:22:40
【问题描述】:

我有一个在线 Parse.com 数据库,我可以创建对象并查询它们,但不能更新。在 Parse.com 文档的 Xamarin 部分中,它只告诉您如何在创建对象后直接更新它,我不想这样做。我尝试调整文档对其他平台的说明,但没有奏效,我还尝试查询数据库并在此之后直接输入新字段值,但它将它们视为单独的函数。有人帮忙吗?

Parse.com 文档:

    // Create the object.
var gameScore = new ParseObject("GameScore")
{
    { "score", 1337 },
    { "playerName", "Sean Plott" },
    { "cheatMode", false },
    { "skills", new List<string> { "pwnage", "flying" } },
};
await gameScore.SaveAsync();

// Now let's update it with some new data.  In this case, only cheatMode
// and score will get sent to the cloud.  playerName hasn't changed.
gameScore["cheatMode"] = true;
gameScore["score"] = 1338;
await gameScore.SaveAsync();

我最近尝试的:

ParseQuery<ParseObject> query = ParseObject.GetQuery("cust_tbl");
IEnumerable<ParseObject> customers = await query.FindAsync();
customers["user"] = admin;
record["score"] = 1338;
await record;

【问题讨论】:

  • 请张贴代码显示您尝试过的内容。

标签: parse-platform xamarin


【解决方案1】:

在您的示例中,您将获得一个对象列表 (IEnumerable),而不是单个对象。相反,尝试这样的事情:

ParseQuery<ParseObject> query = ParseObject.GetQuery("cust_tbl");
// you need to keep track of the ObjectID assigned when you first saved,
// otherwise you will have to query by some unique field like email or username
ParseObject customer = await query.GetAsync(objectId);

customer["user"] = admin;
customer["score"] = 1338;
await customer.SaveAsync();

【讨论】:

  • 非常感谢!我犯了一个愚蠢的错误,这样的帮助。说真的,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-09-14
  • 1970-01-01
  • 1970-01-01
  • 2017-12-15
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
相关资源
最近更新 更多