我想在前言中说我向其他开发人员展示了这一点,他们不知道出了什么问题。
我在Firebase中有一些云功能,而其他所有功能都有效。但是,当我尝试添加另一个函数并使用与其他函数相同的代码访问同一个数据库时,我得到一个“意外的令牌”。错误。这是我的代码:
exports.activateLatestDormantGame = functions.https.onRequest((request, response) => {
var database = admin.database().ref();
var gamesDatabase = database.child('games');
var gameNum;
var gamesDatabaseQuery = gamesDatabase.orderByKey().limitToFirst(1);
gamesDatabaseQuery.once('child_added').then((latestGame) => {
gameNum = parseInt(latestGame.getKey());
gamesDatabaseQuery.off('child_added');
}).then(() => {
gamesDatabase.child(gameNum.toString()).child('isActive').set('true');
response.end();
});
});
exports.tallyVotes = functions.https.onRequest((request, response) => {
var database = admin.database().ref();
var gamesDatabaseQuery = database.child('games').orderByKey().limitToFirst(1);
gamesDatabaseQuery.once('child_added').then((latestGame) => {
return parseInt(latestGame.getKey());
}).then((latestGameKey) => {
var gameDatabaseRef = database.child('games').child(latestGameKey.toString());
var numTeams = gameDatabaseRef.child('teams').child('numTeams').val();
var votes = [];
for (team in numTeams) {
var tallyString = gameDatabaseRef.child('answers').child(team.toString()).val();
var tallyArray = tallyString.split(',');
var highestVote = 0;
for (vote in tallyArray) {
if (parseInt(vote) > highestVote) {
highestVote = parseInt(vote);
}
}
votes.push(highestVote);
}
var questionsAskedString = gamesDatabaseRef.child('questionsAsked').val();
var questionsAskedArray = questionsAskedString.split(',');
var latestQuestion = questionsAskedArray[questionsAskedArray.length - 1];
return [latestQuestion, votes, latestGameKey];
}).then(returnArray) => {
var answer = database.child('questionDatabase').child(returnArray[0]).child('answerIndex').val();
var correctTeams = [];
for (var i = 0; i < returnArray[1].length; i++) {
if (returnArray[1][i] == answer) {
correctTeams.push(i);
}
}
database.child('games').child(returnArray[2]).child('correctTeams').set(correctTeams.join(','));
response.end();
});
});
这是错误:
Error: Error occurred while parsing your function triggers.
/private/var/folders/zm/qyfsj2ms2yd0w2t748s_v16m0000gn/T/fbfn_8186jLVALtYUfzf1/index.js:48
gamesDatabaseQuery.once('child_added').then((latestGame) => {
^
SyntaxError: Unexpected token .
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:588:28)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11
我包含了activateLatestGame函数,以显示我正在重用代码而它无效。我甚至不知道这里的问题是什么,非常感谢任何帮助。
干杯!
答案 0 :(得分:0)
您在此行中缺少 const MyStackNav = (props) => {
const { condition } = props;
return StackNavigator({
Tabs: {
screen: TabNavigator({
Tab1: {
screen: TabScreen1
},
Tab2: {
screen: TabScreen2
},
Tab3: {
screen: TabScreen3
},
...(condition ? {
Tab4: {
screen: TabScreen4
}
} : {})
})
}
StackScreen1: {
screen: StackScreenOne,
},
StackScreen2: {
screen: StackScreenTwo,
},
})
}
:
(
应该是:
}).then(returnArray) => {