我可以获得RSVP数组的承诺:
//if user wants to change username
var promises = [];
promises['username'] = new RSVP.Promise(function(resolve, reject){
if(user.username !== session.username){
//check if username is available
$model_users.getBy({
what:'id',
where: " username = "+db.escape(user.username) +" AND id != "+ db.escape(session.id_user)
})
.then(function(results){
if(!results || results.length <= 0){
//update username is available
$model_users.update({
update:{username: db.escape(user.username)},
where: " id = "+ db.escape(session.id_user)
})
.then(function(success){
confirm.username = 'was_saved';
resolve(success);
},function(err){
reject(err);
console.log('db-error 55299 ' + err);
res.send('db-error');
});
}else{
validation.username = 'error_username_exists';
resolve(validation);
res.send({"validation":validation});
}
},function(err){
reject(err);
console.log('db-error 0299 ' + err);
res.send('db-error');
});
}else{
reject('no username to update - is same to session username');
}
}
//create new JWT and send it back to FE localSTorage
RSVP.all(promises).then(function(){
$model_users.getBy({
what:'id , username',
where: " id = "+ db.escape(session.id_user)
}).then(function(results){
if(results && results.length > 0){
//set new user session and token
var auth = {};
auth.username = results[0].username;
auth.id_user = results[0].id;
auth.session_token = jwt.sign(auth, config.session_secret_key, { expiresInMinutes: config.session_expiration });
res.send({"auth":auth,"confirm":confirm});
}else{
res.send('db-error');
}
},function(err){
console.log('db-error 0.577 '+ err);
});
});
返回的错误是:
RSVP.all(promises).then(function(){
^^^^
SyntaxError: Unexpected identifier
他的可能性如何?我正在关注官方文件https://github.com/tildeio/rsvp.js/#arrays-of-promises
我将它设置在节点app.js:
之上var RSVP = require('rsvp');