2014-01-21 4 views
-1

의 "이"외부 나는이 메시지전화는 초기화

Uncaught TypeError: Cannot call method 'getIdxById' of undefined

를 얻을. 어떻게 접근 할 수 있습니까? 당신은 충분한 정보를 제공하지 않은

function($) { 
    /** 
    * @class test.test.testing 
    */ 

    /** @Static */ 
    { 
     defaults : { 
    columns: [{id: "hello", 
         name: "hello", 
         field: "hello", 
         width: 150, 
         sortable: true, 
         formatter: customFormatter},], 
     } 
    }, 
    /** @Prototype */ 
    { 
    init : function() { 
      this._super(); //the grid 
     } 
    }); 
}); 

var customFormatter = function (row, cell, value, columnDef, dataContext) { 
    var idx = this.dataview.getIdxById(dataContext.id); 
}; 
+0

엄밀히 말하면 우리는 'customFormatter' 함수가 호출되는 범위 또는 호출 될 범위가 무엇인지 추측해야합니까? 올바른 범위를 설정하기 위해'apply()'또는'call()'을 사용하는 것은 아마도 답이지만 누가 알 수 있습니까? – adeneo

+0

형식. 설명. – marekful

+0

방금 ​​편집했습니다 ... –

답변

0

하지만 내 생각은이 변수가 당신이 원하는 설정되지 않는 것입니다 : 이것은 (하는 CustomFormatter 떨어져 열 정의의입니다) 단지 기본 골격이다. Aparently 이것은 지금 정의되지 않았습니다. 코드를 다음과 같이 변경해보십시오 :

var customFormatter = function (me, row, cell, value, columnDef, dataContext) { 
    var idx = me.dataview.getIdxById(dataContext.id); 
}; 
// adding argument for this, and then call: 
customFormatter(this, row, cell, value, columnDef, dataContext); 
+0

'this'는 정의되지 않았지만'this.dataview'는입니다. 'customFormatter'의 컨텍스트에서'this'가 기대하는 것보다 창을 가리킨다 고 추측 할 수 있습니다. –

+0

customFormatter의 위치를 ​​보여주기 위해 방금 편집했습니다. –