JavaScript同步功能

时间:2013-09-12 15:57:24

标签: javascript titanium titanium-mobile

我有以下代码:

ApiClient.prototype.UserLogin = function(data, callback){
    var url = baseURL+'users/login';
    var params = {
        method: 'POST',
        body: data
    };

    function cb(success, response, code){
        if (success === 1){
            response = JSON.parse(response);
           // Save User ID & Username to App Properites to be used for Auth.
            Ti.App.Properties.setString("user_id", response.message._id);
            Ti.App.Properties.setString("username", response.message.username);
            Ti.App.Properties.setString("password", data.password);
            callback(response.success, response, code);
        } else {
            callback(success, response, code);
        }
    }

    this._request(url, params, cb);
};

我遇到了触发回调callback(response.success, response, code)并且尚未设置上述属性的情况。

是否可以使回调仅触发已设置属性的回调?

更新以包含如何调用该函数:

api.UserLogin({
    'password' : password,
    'username' : username
    }, function(success, res, code) {
       if (success == 1) {
          // Do stuff..

0 个答案:

没有答案