dan*_*iel 0 javascript this typescript
Uncaught TypeError: Object #<Object> has no method 'getInvoices'
当我调用this.getInvoicesajax.error 结果时出现错误。如何从那里访问打字稿功能?
// 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?
            }
        });
     }
}
小智 5
检查你的范围。我相信当您调用它时,您实际上是指 ajax 对象而不是类 InvoicesController
public createInvoice() {
      me = this;
      $.ajax({
         ....
        contentType: 'application/json',
        type: 'POST',
        success: function (res) {
            if (res.result === 'ok') {
                console.log('Data saved1');
            }
            else {
                console.log('Save error1');
            }
        },
        error: function (err) {
            me.getInvoices(100,0); // TRY THIS
            console.log("error2"+err);
        }
    });
 }
| 归档时间: | 
 | 
| 查看次数: | 4983 次 | 
| 最近记录: |