1. 程式人生 > >一個js回撥函式的使用例項callback

一個js回撥函式的使用例項callback

            checkModuleUpdate: function (supplier_id, module_type, ver, category_id, callback) {
                var me = this;
                $http({
                    'url': me.options.info_cloud_url + 'rest/Sys/S_Sys_Ota/GetNewVersionV2/?key=' + module_type + '&supplier=' + supplier_id + '&categoryid='
+ category_id, 'method': 'get', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': localStorage.authorization } //transformRequest: transformRequest
}).success(function (moduleVersion) { console.info('伺服器version與本地ver對比', moduleVersion, ver); if (moduleVersion) { if (typeof (moduleVersion.key) != 'undefined') { //轉為整形進行判斷 var
reg=/^\d+$/; if (reg.test(moduleVersion.key) && reg.test(ver)) { if (parseInt( moduleVersion.version) > parseInt(ver)) callback(moduleVersion); } } } }, function () { toast("無法連線伺服器,請檢查您的網路。"); }); },

““““““““““““““““““““`呼叫

 _data.checkModuleUpdate(provider_no, module_model, module_version, module_cateogry, function (moduleVersion) {
                                console.info('moduleVersion,準備升級模組', moduleVersion);
                                //是否要升級模組?跳轉到Login
                                $ionicActionSheet.show({
                                    buttons: [
                                       { text: '確定' }
                                    ],
                                    titleText: '機器端有新的程式可以升級,是否升級?',
                                    destructiveText: '取消',
                                    destructiveButtonClicked: function () {
                                        return true;
                                    },
                                    buttonClicked: function (index) {
                                        //發一個升級指令
                                        me.sendCommand({
                                            command: { command: '1b 00' },
                                            callbacksuccess: function () {
                                                $ionicLoading.show({
                                                    template: '機器端升級中,請勿進行其它操作...'
                                                });
                                            }
                                        });
                                        return true;
                                    }
                                });
                            });