Parse platform 使用React Native在解析中创建具有关系的新对象
似乎没有关于如何创建与使用Parse platform 使用React Native在解析中创建具有关系的新对象,parse-platform,reactjs,react-native,Parse Platform,Reactjs,React Native,似乎没有关于如何创建与使用ParseReact.Mutation.create相关的新解析对象的文档。我求助于: function createRow(relatedObject, data) { ParseReact.Mutation.Create('objectClass', data) .dispatch() .then(function(newRow) { ParseReact.Mutation.AddRelation(newRow, 'relationC
ParseReact.Mutation.create
相关的新解析对象的文档。我求助于:
function createRow(relatedObject, data) {
ParseReact.Mutation.Create('objectClass', data)
.dispatch()
.then(function(newRow) {
ParseReact.Mutation.AddRelation(newRow, 'relationColumn', relatedObject)
});
}
它正在创建新的objectClass
Parse对象,但列relationColumn
不显示与给定relatedObject
的关系
关于如何做到这一点,最好是在一个查询中使用
ParseReact.Mutation.Create
?所以我的代码正在使用ParseReact.Mutation.AddRelation
,如下所示:
ParseReact.Mutation.AddRelation({
"className": newRow.className,
"objectId": newRow.id.objectId}, 'groceryRequestRelation',[{
"__type":"Pointer",
"className":"ClassThePointerPointingTo",
"objectId":"ObjectIdOfClassThePointerIsPointingTo"
}]).dispatch()
@您没有将.dispatch()
放在AddRelation
的末尾,因此这可能是一个问题
另一件我花了很长时间才弄明白的事情是,我在我的AddRelation
中使用了错误的objectId
,我应该使用指针指向的类的objectId
,但是我使用的是关系所属类的objectId
如果这仍然不适用于您,请尝试其他方法:
var data = {
"groceryRequestRelation":{"__op":"AddRelation",
"objects":
[{
"__type":"Pointer",
"className":"ClassThePointerIsPointingTo",
"objectId":"ObjectIdOfClassThePointerIsPointingTo"
}
]
}
};
var url = "https://api.parse.com";
url += "/1/classes/Classname/objectId";
fetch(url, {
method: 'put',
headers: {
'Accept': 'application/json',
'X-Parse-Application-Id': PARSE_APP_ID,
'X-Parse-REST-API-Key': PARSE_REST_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then((response) => {
console.log("inside add relation rest")
console.log(response);
return response.json();
})
.then((responseText) => {
console.log(responseText);
})
.catch((error) => {
console.warn(error);
})
.done();
为AddRelation添加dispatch()对我来说是个好办法。谢谢凯文!还可以将对象数组作为AddRelation中的最后一个参数传递。例如,如果要将用户对象数组添加到类中,则可以传递该数组。@app np,很高兴提供帮助!