0
遊戲結構: Parse.com雲代碼中找到相關的內容
objectId - String name - String genres - Array遊戲數據:
ObjectId name genres ===================================== 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'); });我如何去獲得基於流派在relatedGames變量來存儲相關的遊戲嗎?
例如:
if req.params.name = AAA then relatedGames = CCC, EEE if req.params.name = BBB then relatedGames = CCC if req.params.name = CCC then relatedGames = AAA, BBB使用 「containedin」的在equalTo的「成功」的功能,如下圖所示,但它沒有工作,我已經試過。
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'); });