2013-10-25 3 views
7

autoLoad: true이라는 저장소에 연결된 그리드가 있습니다. 문제는 메뉴를 통해 나중에 액세스 할 때만보기가 만들어 지더라도 저장소가 응용 프로그램 시작시로드된다는 것입니다.extjs - autoload가있는 저장소가 응용 프로그램 시작시로드되지 않아야합니다.

나는 Application.js와 뷰에서 저장소를 참조했지만 저장소 나 뷰를 명시 적으로 instatiating하지는 않습니다.

뷰가 필요할 때만 저장소를로드하는 방법을 모르겠습니다.

  • autoLoad: true으로 설정하면 응용 프로그램 실행시 저장소가로드됩니다.
  • autoLoad: false으로 설정하면 저장소가 전혀로드되지 않습니다.

나는 이것이 매우 기본적인 것임을 알고 있지만, 나는 지금까지 붙어있다. 여기


가 참조 할 수 있도록 모든 관련 코드 :
응용 프로그램/저장/Owners.js

Ext.define('Mb.store.Owners', { 
    extend: 'Ext.data.Store', 
    model: 'Mb.model.Owner', 
    autoLoad: true, 
    proxy: { 
     ... 
}); 

Application.js

Ext.define('Mb.Application', { 
    name: 'Mb', 
    extend: 'Ext.app.Application', 
    models: [ 
     'Owner' 
    ], 
    stores: [ 
     'Owners' 
    ], 
    ... 

응용 프로그램 /보기/Owners.js

Ext.define('Mb.view.winbiz.Owners', { 
    extend: 'Ext.grid.Panel', 
    alias: 'widget.test-gridPanel', 
    store: 'winbiz.Owners', 
    columns: [{ 
    ... 

뷰는 컨트롤러에서 인스턴스화 :

Ext.define('Mb.controller.Winbiz', { 
    extend: 'Ext.app.Controller', 
    views: [ 
     'Owners' 
    ], 
    init: function(){ 
     this.control({ 
      'menu #test': {click: this.onMenuTest}, 
     }) 
    }, 
    onMenuTest: function(){ 
     this.getController('Main').addToMainTab('test-gridPanel'); 
    }, 

답변

6

당신은 저장 load 메서드를 호출하고 autoLoad을 해제 할 볼 render 핸들러를 추가 할 수 있습니다.

예 리스너 :

Ext.define('Mb.view.winbiz.Owners', { 
    extend: 'Ext.grid.Panel', 
    [...], 

    initComponent: function(){ 
     this.callParent(); 
     this.on('render', this.loadStore, this); 
    }, 

    loadStore: function() { 
     this.getStore().load(); 
    } 
}); 
+0

감사합니다. 이것은 완벽한 해결책입니다. –

+4

보기의 코드가 마음에 들지 않습니다. 보기에서 컨트롤러의 책임이되어야하는 코드가있는 경우 컨트롤러를 사용할 이유가 없습니다. 또한이 솔루션은보기의 모든 렌더링에 저장소를 다시로드합니다. – oldwizard

1

내가보기의 컨트롤러가 가게로드를 처리 할 것입니다.

저장소에서 자동로드를 사용 중지하는 것으로 시작하십시오.

Ext.define('Mb.controller.Winbiz', { 
    extend: 'Ext.app.Controller', 
    views: [ 
     'Owners' 
    ], 
    ownerStore: null, 
    init: function(){ 
     this.control({ 
      'menu #test': {click: this.onMenuTest}, 
     }); 

     this.ownerStore = Ext.getStore('winbiz.Owners'); 
    }, 
    onMenuTest: function() { 
     if (this.ownerStore.loaded === false) { 
      this.ownerStore.load(
       scope: this, 
       callback: this.onOwnerStoreLoaded 
      ); 
     } 
     else { 
      this.addToTab(); 
     }    
    }, 
    onOwnerStoreLoaded: function (store, records, successful, eOpts) { 
     if (successful) { 
      store.loaded = true; 
      this.addToTab(); 
     } 
    }, 
    addToTab: function() { 
     this.getController('Main').addToMainTab('test-gridPanel'); 
    } 

저장소가로드되기 전이나 후에보기를 변경하려는 Wheet은 다른 질문입니다.

+0

코드가 컨트롤러에 들어가야하므로 상점을 다시로드하지 않아야합니다. 당신의 코드는 어떻게 든 길다. 나는 그것을 더 짧게하려고 노력할 것이다. –

0

이 내 마지막 컨트롤러 코드 : 그것은 제안 @pcguru에 의해 컨트롤러에 모든 코드를두고 @Lolo에 의해 제안 코드를 단축하기 위해 렌더링 이벤트를 사용

Ext.define('Mb.controller.Winbiz', { 
    extend: 'Ext.app.Controller', 
    views: [ 
     'Owners' 
    ], 
    refs: [{ref: 'testGrid', selector: 'test-gridPanel'}], 
    init: function(){ 
     this.listen({ 
      store: { 
       '#Owners':{ load: this.onOwnersLoad} 
      } 
     }) 
     this.control({ 
      'menu #test': {click: this.onMenuTest}, 
      'test-gridPanel': {render: this.onOwnersRender} 
     }) 
    }, 
    onMenuTest: function(){ 
     this.getController('Main').addToMainTab('test-gridPanel'); 
    }, 
    onOwnersLoad: function(store){ 
     store.loaded = true 
    }, 
    onOwnersRender: function(){ 
     var store = this.getTestGrid().getStore(); 
     if(!store.loaded)store.load(); 
    }, 

. 감사합니다.

+0

'.loaded'가 코드에 설정되어 있지 않으면 항상 저장소가로드됩니다. – oldwizard

+0

@pcguru 네 말이 맞아. 따라서 저장소로드시이 변수를 저장하지 않으면 저장소가 이미로드되었는지 알 수있는 방법이 없습니다. –

+1

@pcguru이 문제를 해결하기 위해 코드를 업데이트했습니다. 이제 더 이상 당신의 것보다 짧습니다 : ( –

관련 문제