當我在ajax.error結果中調用this.getInvoices
時,出現錯誤Uncaught TypeError: Object #<Object> has no method 'getInvoices'
。我如何從那裏訪問打字稿功能?Javascript函數中的調用手稿函數
// Typescript
class InvoicesController {
...
public getInvoices(skip: number, take: number): void {
...
}
public createInvoice() {
$.ajax({
...
contentType: 'application/json',
type: 'POST',
success: function (res) {
if (res.result === 'ok') {
this.getInvoices(0,100); // THIS DOES NOT WORK?
}
},
error: function (err) {
this.getInvoices(0,100); // THIS DOES NOT WORK?
}
});
}
}
可能重複[$(this)裏面的AJAX成功不工作](http://stackoverflow.com/questions/6394812/this-inside-of-ajax-success-not-working) –
沒有這個必須做的打字稿 – daniel
不,它沒有。 TypeScript編譯爲JavaScript。將'context'參數傳遞給'$ .ajax()'。 –