使用Unity Developer Guide中的示例代码解析 @ https://www.parse.com/docs/unity_guide#objects-updating
// Create the object.
var gameScore = new ParseObject("GameScore")
{
{ "score", 1337 },
{ "playerName", "Sean Plott" },
{ "cheatMode", false },
{ "skills", new List<string> { "pwnage", "flying" } },
};
gameScore.SaveAsync().ContinueWith(t =>
{
// 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;
它只是添加一个新行并保持原始行不变 我想我认为Parse会做一些“像SQL一样的事情”,比如UPDATE,其中primaryKey = 123.
正在寻找答案我找到了这段代码@ https://parse.com/questions/updating-a-field-without-retrieving-the-object-first,但C#中没有例子。将此移植到C#的所有尝试都会导致多个语法错误。
UnityScript:
// Create a pointer to an object of class Point with id dlkj83d
var Point = Parse.Object.extend("Point");
var point = new Point();
point.id = "dlkj83d";
// Set a new value on quantity
point.set("quantity", 6);
// Save
point.save(null, {
success: function(point) {
// Saved successfully.
},
error: function(point, error) {
// The save failed.
// error is a Parse.Error with an error code and description.
}
});
Parse是否有某种方法可以使用C#更新已存在的行?它在文档中的位置是什么?他们自己的榜样怎么会这么无用?
答案 0 :(得分:0)
其中一个与我的问题相关的帖子说“检索对象,然后用更改写回来”,我不知道如何执行所述目标(特别是在Parse Documentation的示例代码的史诗失败之后)
以下是我能够找到并做出的工作:
var query = new ParseQuery<ParseObject>("Tokens")
.WhereEqualTo ("objectId", "XC18riofu9");
query.FindAsync().ContinueWith(t =>
{
var tokens = t.Result;
IEnumerator<ParseObject> enumerator = tokens.GetEnumerator();
enumerator.MoveNext();
var token = enumerator.Current;
token["power"] = 20;
return token.SaveAsync();
}).Unwrap().ContinueWith(t =>
{
// Everything is done!
//Debug.Log("Token has been updated!");
});
第一部分使用声明的objectId检索对象,第二部分设置对象中的字段。第三部分报告所有操作都很顺利。
这是一只猴子看到,猴子在这一点上的理解是因为我不理解代码中的细节。
可以通过创建名为“Tokens”的类来测试代码。在该类中创建一个tokenName字段和一个幂字段。用火,水,泥作为tokenNames做几行。使用有效的objectId或您喜欢的任何其他搜索参数替换.WhereEqualTo子句中的objectId。执行代码并观察解析数据浏览器中的更改。
要获得额外的功劳,请创建从Parse文档的“链接任务一起”部分实现示例代码所需的类。