2014-02-21 70 views
-2

我可以承諾的RSVP陣列工作:節點,RSVP.js陣列

//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 =需要( 'RSVP');

回答

1

您錯過了一個)上面兩行RSVP.all(promises)...

考慮使用linter,它會立即捕獲這種錯誤。見例如SublimeLinter