Parse.com:如何编辑数组

时间:2015-12-21 14:37:46

标签: c# parse-platform xamarin

现在有几天困扰我的事情: 我有一个名为House的Object,在这个对象里面我有一个指向我房间的数组。

假设我想从房子里搬走一个房间。

我可以手动完成:转到数据浏览器,从他的“表格”中移除房间并编辑删除条目的数组。

我可以从代码中删除:从House.Rooms列表中移除房间并提交解析。

问题是,在我删除这个房间后,我试图让房子有一个包含房间,Parse将不会返回房间。我将只返回数组代码。

请注意,在删除房间之前,一切正常。

这是一些伪代码:

Room : ParseObject
...
House : ParseObject
...

var rooms = new List<Room>();
rooms.Add(Kitchen);
rooms.Add(BathRoom);
rooms.Add(BedRoom);
rooms.Add(BedRoomCouple);

ParseObject house = new House;
house.Rooms = rooms;
await house.SaveAsync();

await fullHouseFromParse = ParseQuery<House>().Include("rooms").FindAsync();

// House.Rooms will be filled with all data.
// For example, House.Rooms[0].Name will be filled 

Now, try to delete some rooms:

...
await houseFromParse = ParseQuery<House>().Include("rooms").FindAsync();
await rooms = ParseQuery<Room>().FindAsync();
rooms.Add(Kitchen);
rooms.Add(BathRoom);
rooms.Add(BedRoom);
rooms.Add(BedRoomCouple);

rooms.Remove(0,1)
await rooms.SaveAsync();

houseFromParse.Rooms = rooms;
await house.SaveAsync();

await fullHouseFromParse = ParseQuery<House>().Include("rooms").FindAsync();
// here the house won't have the rooms.

即使您去Parse.com Web Api并试图获得房间,它将返回的全部是

{
    "ACL": {
        "role:5x6u4LxXlV_cad": {
            "read": true,
            "write": true
        }
    },
    "createdAt": "2015-12-17T17:47:51.021Z",
    "description": "House",
    "name": "House",
    "objectId": "[someId]",
    "owner": {
        "__type": "Pointer",
        "className": "_User",
        "objectId": "[someId]"
    },
    "rooms": [
        {
            "objectId": "bTLjAWAufj"
        }
    ],
    "updatedAt": "2015-12-21T13:56:57.429Z"
}

0 个答案:

没有答案