1

我有以下代码:

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..
4

0 回答 0