2012-06-04 3 views
0

저는 extjs에 익숙하지 않고 Ext.data.store()의 레코드 수에 따라 동적 화면을 만드는 중이었습니다. getTotalCount/getCount는 저장소에서 레코드를 가져 오는 데 사용됩니다. 나는 VAR의 레코드의 총을 저장하고 나는 항상로 tsize에 널 얻을이저장소에있는 레코드가 없습니다.

function Get_count() 
{ 
    var num;        
    CacheStore.on({ 

      'load':{ 

      fn : function(store,records,options){ 
        num = getTotalCount(); 
        //console.info('Store count = ', tsize); 
        //console.info(' count = ', getCount()); 
      }, 
      scope: this 
    }, 
    'loadexception' : { 
      fn : function (obj,options,response,e){ 
        //console.info('error = ', e); 
      }, 
    scope : this 
    } 

}); 

    // this is a wrong logic but have to do something similar 
    //return num; //return num 

    }; 
    tsize = Get_count(); 

처럼 뭔가를 시도하고 그것을

를 반환해야합니다. getTotalCount() 대신 getCount() 시도했지만 같은 문제가 발생합니다. 나는 당신의 논리가 조금 여기 찌르고입니다 잘못

답변

1

하겠어 어디

는 잘 모릅니다. 저장소로드가 끝나면 연결될 저장소에 수신기를 추가하는 함수를 시작할 수 없습니다. (잘 할 수는 있지만 이것은 미묘한 버그 다.)

는 당신이 필요가있는 무엇을

cacheStore =Ext.create... 
cacheStore.on('load',function(store,records,e){ 
    //dosomestuff that needs the count 
    var num= store.totalCount() 
    //now you use the num in here, else you create an async error 

    //or you can ... 
    my.someFunc(num); 
    //in here, but you can only run it after the store has loaded 
},this); 
+0

안녕 알렉스가 나는 그것을 사용했습니다. 당신이 번호를 사용 싶어하는 기능을 포함하고 당신이 그것을 만들 가게에 리스너를 선언하지만 난 오류를 얻고있다 "null이 null이거나 객체가 아닙니다." –