-1
我正在爲我的項目使用angular.js,並且我編寫了一個服務,其中我有返回患者詳細信息,但在控制器中,我沒有通過patientinfo()函數調用獲取此返回值。 這裏是我的服務代碼:如何將我的函數返回值傳遞給父函數
app.service('PatientDetailService', function() {
this.patientinfo = function(){
$.ajax({
dataType: "json",
url: "json/client_info.json",
type: 'get',
error: function(patientdetail){ alert("error");},
success: function(patientdetail){
alert("successs");
console.log(patientdetail);
return patientdetail;
}
});
}
});
:請你解釋一下如何處理結果的一些其他功能,因爲我不知道如何處理這個值,我不能得到我的結果。 – 2013-03-11 09:16:07
而是從'patientinfo'返回一個結果,它應該接受一個可以在結果可用時調用的函數。尋找解釋JavaScript中異步編程的教程(使用回調)。 [這一個](http://recurial.com/programming/understanding-callback-functions-in-javascript/)似乎很好,但你可能會發現另一個更有幫助。 – 2013-03-11 09:26:52