ajax异步举例
SelectInfo = { release_url: "/compatible/getReleaseFor", project_url: "/compatible/getProjectInfo", init:function (){ this.initReleaseInfo(); this.initProjectInfo(); }, initReleaseInfo: function (){ //var datas = this.getReleaseInfo(this.release_url); this.getSelectInfo(this.release_url, true, function(datas) { var selectDiv = $("#compatibletest-release-select"); selectDiv.append("<option></option>"); for(var i=0;i<datas.length;i++){ var data = datas[i]; var html = '<option name=\"'+data +'\">' + data + '</option>'; selectDiv.append(html); } }); }, initProjectInfo: function (){ //var datas = this.getReleaseInfo(this.release_url); this.getSelectInfo(this.project_url, true, function(datas) { var selectDiv = $("#compatible-project-select"); selectDiv.append("<option></option>"); for(var i=0;i<datas.length;i++){ var data = datas[i]; var html = '<option name=\"'+data +'\">' + data + '</option>'; selectDiv.append(html); } }); }, beforeShow: function () { var thiz = this; $('#' + this.domId).on('show.bs.modal', function(event){ var branchUrl = $("#branch-url-span").html(); $("#qmstest-branch").val(branchUrl); TestCaseSuite.list(true, function(datas){ var qmsTestTypeDiv = $("#qms-test-type-div"); for(var i=0; i<datas.length; i++) { var data = datas[i]; var html = '<div class="checkbox">' + '<label>' + '<input type="checkbox" name="input-qms-testccasesuites-checkbox" value="' + data.id + '" checked>' + data.name + '</label>' + '</div>'; qmsTestTypeDiv.append(html); } }); }); }, getSelectInfo: function (url,async,func) { if (async == null || async == undefined) { async = true; } var datas = null; $.ajax({ type: "GET", url: url, async: async, success : function(result) { if (result.code != "SUCC") { var title = "release选项数据获取失败"; var errorMsg = "[" + result.code + "] " + result.data.errMsg; toastr.error(errorMsg, title); return; } datas = result.data; if (func != undefined && $.isFunction(func)) { func(datas); } } }); return datas; }, }