Parse platform Parse.com云代码查找相关内容

Parse platform Parse.com云代码查找相关内容,parse-platform,parse-cloud-code,Parse Platform,Parse Cloud Code,游戏结构: objectId - String name - String genres - Array objectId字符串 名称字符串 类型-数组 奥运会数据: ObjectId name genres ===================================== gawtttBGc2 AAA ["a", "d"] gawtttBGc9 BBB ["b", "p"] gawtutrGc

游戏结构: objectId - String name - String genres - Array objectId字符串 名称字符串 类型-数组 奥运会数据: ObjectId name genres ===================================== gawtttBGc2 AAA ["a", "d"] gawtttBGc9 BBB ["b", "p"] gawtutrGc4 CCC ["a", "b", "d"] gawttuowc7 EEE ["d"] 对象名称类型 ===================================== gawtttBGc2 AAA[“a”,“d”] gawtttBGc9 BBB[“b”,“p”] gawtutrGc4 CCC[“a”、“b”、“d”] gawttuowc7 EEE[“d”] 云代码: var gQuery = new Parse.Query(Games); var foundGame; var relatedGames; gQuery.equalTo('name', req.params.name).first({ success: function(game) { foundGame = game; }, error: function(error) { return []; } }).then(function() { res.render('games/show', { game: foundGame, relatedGames: relatedGames }); }, function() { res.send(500, 'Failed finding'); }); var gQuery=newparse.Query(游戏); 虚拟现实游戏; var相关博弈; gQuery.equalTo('name',req.params.name)。第一个({ 成功:功能(游戏){ foundGame=游戏; }, 错误:函数(错误){ 返回[]; } }).然后(函数(){ res.render(“游戏/表演”{ 游戏:foundGame, 相关游戏:相关游戏 }); }, 函数(){ res.send(500,“查找失败”); }); 如何将基于类型的相关游戏存储在relatedGames变量中

例: 如果req.params.name=AAA,则 相关游戏=CCC,EEE 如果req.params.name=BBB,则 相关游戏 如果req.params.name=CCC,则 相关游戏=AAA,BBB 我曾尝试在equalTo的“success”函数中使用“containedIn”,如下所示,但没有成功。 var gQuery = new Parse.Query(Games); var foundGame; var relatedGames; gQuery.equalTo('name', req.params.name).first({ success: function(game) { foundGame = game; var newQuery = new Parse.Query(Games); newQuery.containedIn('genres', foundGame.get('genres')).find({ success: function(results){ relatedGames = results; }, error: function(error){ console.log(error); } }); }, error: function(error) { return []; } }).then(function() { res.render('games/show', { game: foundGame, relatedGames: relatedGames }); }, function() { res.send(500, 'Failed finding'); }); var gQuery=newparse.Query(游戏); 虚拟现实游戏; var相关博弈; gQuery.equalTo('name',req.params.name)。第一个({ 成功:功能(游戏){ foundGame=游戏; var newQuery=newparse.Query(游戏); newQuery.containedIn('genres',foundGame.get('genres')).find({ 成功:功能(结果){ 相关游戏=结果; }, 错误:函数(错误){ console.log(错误); } }); }, 错误:函数(错误){ 返回[]; } }).然后(函数(){ res.render(“游戏/表演”{ 游戏:foundGame, 相关游戏:相关游戏 }); }, 函数(){ res.send(500,“查找失败”); });

玩弄了“承诺”,并且能够让它发挥作用。 var gQuery = new Parse.Query(Games); var foundGame; var relatedGames; gQuery.equalTo('nameShort', req.params.name).find().then(function(games) { foundGame = games[0]; var promise = Parse.Promise.as(); promise = promise.then(function(){ return gQuery.containedIn('genres', foundGame.get('genres')).find().then(function(results) { relatedGames = results; return Parse.Promise.as('Find Related Games'); }); }); return promise; }).then(function() { res.render('games/show', { game: foundGame, relatedGames: relatedGames }); }, function() { res.send(500, 'Failed finding'); }); var gQuery=newparse.Query(游戏); 虚拟现实游戏; var相关博弈; gQuery.equalTo('nameShort',req.params.name).find().then(函数(游戏){ foundGame=游戏[0]; var promise=Parse.promise.as(); promise=promise.then(函数(){ 返回gQuery.containedIn('genres',foundGame.get('genres')).find().then(函数(结果){ 相关游戏=结果; 返回Parse.Promise.as('Find Related Games'); }); }); 回报承诺; }).然后(函数(){ res.render(“游戏/表演”{ 游戏:foundGame, 相关游戏:相关游戏 }); }, 函数(){ res.send(500,“查找失败”); });

仍在试图进一步了解“承诺”是如何准确工作的,但希望这对其他人有所帮助

var gQuery = new Parse.Query(Games); var foundGame; var relatedGames; gQuery.equalTo('nameShort', req.params.name).find().then(function(games) { foundGame = games[0]; var promise = Parse.Promise.as(); promise = promise.then(function(){ return gQuery.containedIn('genres', foundGame.get('genres')).find().then(function(results) { relatedGames = results; return Parse.Promise.as('Find Related Games'); }); }); return promise; }).then(function() { res.render('games/show', { game: foundGame, relatedGames: relatedGames }); }, function() { res.send(500, 'Failed finding'); });