我必须在我的数据浏览器中解析类,'详细信息'和'内容'。 '细节' class有以下 - > ' objectId',' uuid'并且'接近' '内容'课程有' objectId',' descId'和'提供'。
我使用Javascript SDK创建了一个Web UI,因此当用户输入uuid时,邻近度和优惠,uuid和proximity将存储在'详细信息中。 class,成功后我获得新创建的对象的objectId。然后我将该objectId存储在'内容' descId下的类和用户输入的商品。
我的问题是我有一个需要填充的html表,所以我需要从两个类中提取数据。来自'细节'的uuid和接近度和来自内容的提议'所以我需要在一个查询中执行此操作。这是我存储'详细信息的原因。 objectId在'内容' class作为一种外键。
我被困在这条十字路口,并尝试过包括等等,但我只是在尝试,我不知道自己需要做什么。如果有人可以提供帮助,也许可以给我看一个样本,我非常感激
这是我的js保存代码:
//Creating Beacon Content Parse Object
var iBeaconContent = Parse.Object.extend("Content");
var beaconContent = new iBeaconContent();
//Creating Object to save to iBeacon Description Table
var iBeaconDescription = Parse.Object.extend("Details");
var beaconDescription = new iBeaconDescription();
beaconDescription.set("uuid", tdUuid.children("input[type=text]").val().toString());
beaconDescription.set("proximity", parseInt(tdProximity.children($('prox')).val().toString()));
beaconDescription.save(null, {
success: function(beaconDescriptionObject) {
var query = new Parse.Query("Details");
query.equalTo("uuid", tdUuid.children("input[type=text]").val().toString());
query.find({
success: function(results) {
objectId = results[0].id;
beaconContent.set("descId", objectId);
beaconContent.set("offer", tdOffer.children("input[type=text]").val().toString());
beaconContent.save(null, {
success: function(object) {
document.location.reload(true);
}, error: function(beaconContent, error) {
}
});
}
});
},
error: function(error) {
}
});
新JAVASCRIPT
var BeaconDetail = Parse.Object.extend("Details");
var BeaconContent = Parse.Object.extend("Content");
var innerQuery = new Parse.Query(BeaconDetail);
innerQuery.exists("descId");
var query = Parse.Query(BeaconDetail);
query.matchesQuery("objectId", innerQuery);
query.find({
success:function(beaconContent){
alert("Success----lenght: " + beaconContent.length);
}
})
答案 0 :(得分:2)
听起来像是需要使用复合查询或关系查询。这是一些链接
https://www.parse.com/docs/js_guide#queries-relational
https://www.parse.com/docs/js_guide#queries-compound
https://parse.com/questions/compound-relational-queries
来自两个类的查询示例如下
看到代码也很好,这有助于给出更相对的答案。
CODE
var lotsOfWins = new Parse.Query("Player");
lotsOfWins.greaterThan("wins", 150);
var fewWins = new Parse.Query("Player");
fewWins.lessThan("wins", 5);
var mainQuery = Parse.Query.or(lotsOfWins, fewWins);
mainQuery.find({
success: function(results) {
// results contains a list of players that either have won a lot of games or won only a few games.
},
error: function(error) {
// There was an error.
}
});
答案 1 :(得分:0)
如果我理解正确,您的Content
类包含指向Details
属性中descId
类的指针,并且您希望能够根据某些Details
进行查询}字段并返回两个对象?
注意:我必须指出descId
是一个名字很差的财产,只会引起混淆。如果它是指针,只需给它命名为desc
,不要使用Id
后缀。
无论如何,如果那是你想要的:
var query = new Parse.Query("Content");
var uuid = tdUuid.children("input[type=text]").val().toString();
var proximity = parseInt(tdProximity.children($('prox')).val().toString());
// consider logging those two variable to confirm they're what you want
// query properties of a pointer
query.equalTo("descId.uuid", uuid);
query.equalTo("descId.proximity", proximity);
// include the pointer in the output
query.include("descId");
query.find({
success: function(beaconContent) {
alert("Success -- length: " + beaconContent.length);
// sample output of first result:
var content = beaconContent[0];
var detail = content.get("descId");
console.log("uuid", detail.get("uuid"));
console.log("proximity", detail.get("proximity"));
console.log("offer", content.get("offer"));
}
});