在我的一个文件中,我拨打电话如下:
var jobsString = getDropdownJobs();
它调用这个函数:
function getDropdownJobs() {
var jobsString = amplify.store("JobsList");
if (typeof jobsString === 'undefined') {
// Amplify sends a request for getJobs, if it exists in cache, it will return that value.
// If it does not exist in cache, it will make the AJAX request.
amplify.request("getJobs", function (data) {
// Leave a blank option for the default of no selection.
var jobsString = '<option value=""></option>';
// Append each of the options to the jobsString.
$.each(data.jobs, function () {
jobsString += "<option " + "value=" + this.JobNo_ + ">" + this.JobNo_ + " : " + this.Description + this.Description2 + "</option>";
});
// Store the jobsString to be used later.
amplify.store("JobsList", jobsString);
});
}
return jobsString;
}
其中放大定义"GetJobs"
为:
amplify.request.define("getJobs", "ajax", {
url: "../api/Job/Jobs",
dataType: "json",
type: "GET",
cache: "persist"
});
每当它返回时,它都是未定义的。我在 AJAX 定义中添加了“async: false”,它并没有改变任何东西。
在返回之前如何确保该值存在?