2012-06-16 2 views
1

AJAX 요청에 의해 그리드에 응답 된 JSON 데이터를로드하려고합니다. 내 가게 정의 :이ExtJS store.loadData()가 JSON 데이터를로드하지 않습니다.

Ext.define('Report.store.CustomerDataStore', { 
    extend: 'Ext.data.Store', 
    requires: [ 
     'Report.model.Customer' 
    ], 

    constructor: function(cfg) { 
     var me = this; 
     cfg = cfg || {}; 
     me.callParent([Ext.apply({ 
      autoLoad: false, 
      storeId: 'CustomerDataStore', 
      model: 'Report.model.Customer', 
      proxy: { 
       type: 'ajax', 
       url: '', 
       reader: { 
        type: 'json', 
        root: 'data', 
        record: 'fields' 
       } 
      } 
     }, cfg)]); 
    } 
}); 

로 정의 내 응용 프로그램에서 버튼을 다음과

xtype: 'button', 
handler: function(button, event) { 
    var queryform = this.up('form').getForm(); 
    var me = this; 
    if(queryform.isValid()) 
    { 
     Ext.Ajax.request({ 
      url: 'customers/', // where you wanna post 
      success: function(response) { 
       var mystore = Ext.data.StoreManager.lookup('CustomerDataStore'); 
       var myData = Ext.JSON.decode(response.responseText); 
       console.log(myData.toSource()); 
       mystore.loadData(myData); 
      }, 
      jsonData: Ext.JSON.encode(queryform.getValues()) 
     }); 
    } 
}, 

문제는 내 그리드는 응답 데이터를 표시하지 않는다는 것입니다! 내가 답장 한 JSON 형식이 괜찮을 것이라고 확신합니다. json 파일로 확인했습니다. 또한 myData.toSource()은 원하는 JSON 형식을 반환합니다. 내가 뭘 잘못하고 있는지 혼란 스럽네요?

도움을 주시겠습니까?

답변

8

해결책을 찾았으므로 loadData() 대신 loadRawData() 함수를 사용해야했습니다.

3

loadData()은 모델 즉 레코드를로드하고 내부에서 JSON 데이터를 구문 분석하지 않습니다. 프록시 리더에서 JSON 형식을 지정한 다음 저장소에서 호출 할 때 자동으로 Ajax 호출을 수행해야합니다. store.load()

+0

그러나이 방법으로 내 저장소 정의에서 'url'매개 변수를 선언해야합니다. 내가 맞습니까? Ext.AJAX.request 응답에서 데이터를로드하도록 저장소에 지시하는 방법은 무엇입니까? –

+0

'ajax'유형의 프록시가 이미 있고 그 아래 url이 비어 있습니다. 그냥 URL을 채우고'Ext.AJAX.request' 대신'store.load()'를 호출하십시오. – MarthyM

관련 문제