2017-12-13 1 views
0

페이징 및 다른 용도로 ExtJS 버퍼가있는 저장소를 사용하고 있습니다. 버퍼링 된 저장소에 데이터를로드하려고합니다. 일반 상점에서 나는버퍼 된 저장소에 데이터를 설정하는 방법

store.loadData(thistore.data.items);

를 사용할 수 있지만 버퍼 저장소에 나는 loadData을 사용할 수 없습니다. 내 코드 당 나는 응답으로 데이터를 받고 있지만 데이터를 설정하는 방법을 모르겠다 볼 수 있습니다. 도울 수있는 loadData의 대체물은 Ext.data.BufferedStore

+1

그렇지 않습니다. 원격 소스에서 가져온 대용량 데이터 세트입니다. –

+0

A [BufferedStore'] (https://docs.sencha.com/extjs/6.5.2/classic/Ext.data.BufferedStore.html)에서'loadData()'를 사용할 필요가 없다고 생각합니다. 왜냐하면 A 'BufferedStore'는 초대형 서버 측 데이터 세트에 상응하는 드문 드문 채워진 페이지 맵을 유지합니다. 그것은'서버 측 'API와 직접 연결된다는 것을 의미합니다. 'loadData()'를 사용하려면이''store' (https://docs.sencha.com/extjs/6.5.2/classic/Ext.data.Store.html)을 사용해야합니다. –

답변

0

store.load method을 사용해 보셨습니까?

store.load({ 
     callback: function(records, operation, success) { 
      console.log(records); 
     } 
    }); 

UPDATE는this 엽차의 예를 바탕으로

, 난 당신에 extjs에게 6.5.2 고전을 사용하는 예를 만들었습니다. 현대 virtualstorebufferedstore 대신 사용되고 있기 때문에 고전적인 툴킷을 사용했습니다. 관심의

Ext.define('ForumThread', { 
    extend: 'Ext.data.Model', 
    fields: [{ 
     name: 'title', 
     mapping: 'topic_title' 
    }, { 
     name: 'forumtitle', 
     mapping: 'forum_title' 
    }, { 
     name: 'forumid', 
     type: 'int' 
    }, { 
     name: 'username', 
     mapping: 'author' 
    }, { 
      name: 'replycount', 
      mapping: 'reply_count', 
      type: 'int' 
    }, { 
      name: 'lastpost', 
      mapping: 'post_time', 
      type: 'date', 
      dateFormat: 'timestamp' 
    }, 
     'lastposter', 'excerpt', 'topic_id' 
    ], 
    idProperty: 'post_id' 
}); 

var store = Ext.create('Ext.data.BufferedStore', { 
    id: 'store', 
    model: 'ForumThread', 

    // The topics-remote.php script appears to be hardcoded to use 50, and ignores this parameter, so we 
    // are forced to use 50 here instead of a possibly more efficient value. 
    pageSize: 50, 

    // This web service seems slow, so keep lots of data in the pipeline ahead! 
    leadingBufferZone: 1000, 
    proxy: { 
     // load using script tags for cross domain, if the data in on the same domain as 
     // this page, an HttpProxy would be better 
     type: 'jsonp', 
     url: 'https://www.sencha.com/forum/topics-remote.php', 
     reader: { 
      rootProperty: 'topics', 
      totalProperty: 'totalCount' 
     }, 
     // sends single sort as multi parameter 
     simpleSortMode: true, 

     // Parameter name to send filtering information in 
     filterParam: 'query', 
    }, 
    remoteFilter: true, 
    autoLoad: false 
}); 

function onSearchParamApplied() { 
    var searchParam = grid.down('#txtSearchParam').getValue(); 

    var store = grid.getStore(); 
    if (!store) 
     return; 

    store.getProxy().extraParams['query'] = searchParam; 

    store.reload({ 
     callback: function (records, operation, success) { 
      grid.down('#status').setValue(store.getTotalCount()); 
     } 
    }); 
} 

function onStoreLoadClick() { 
    var store = grid.getStore(); 
    if (!store) 
     return; 

    store.load({ 
     callback: function (records, operation, success) { 
      grid.down('#status').setValue(store.getTotalCount()); 
     } 
    }); 
} 

var grid = Ext.create('Ext.grid.Panel', { 
    width: 700, 
    height: 470, 
    padding: 10, 
    collapsible: true, 
    title: 'ExtJS.com - Browse Forums', 
    store: store, 
    loadMask: true, 
    dockedItems: [{ 
     dock: 'top', 
     xtype: 'toolbar', 
     items: [{ 
      xtype: 'textfield', 
      itemId: 'txtSearchParam', 
      width: 400, 
      fieldLabel: 'Search', 
      labelWidth: 50, 
     }, { 
      xtype: 'button', 
      iconCls: 'x-fa fa-search', 
      tooltip: 'Reload buffered store with the new param', 
      handler: onSearchParamApplied 
     }, { 
      xtype: 'button', 
      text: 'loadGrid', 
      handler: onStoreLoadClick 
     },'->', { 
      xtype: 'displayfield', 
      itemId: 'status', 
      fieldLabel: 'Count ', 
      value: '0' //initial value 
     }] 
    }], 
    selModel: { 
     pruneRemoved: false 
    }, 
    multiSelect: true, 
    viewConfig: { 
     trackOver: false, 
     emptyText: '<h1 style="margin:20px">No matching results</h1>' 
    }, 
    // grid columns 
    columns:[{ 
     xtype: 'rownumberer', 
     width: 50, 
     sortable: false 
    },{ 
     tdCls: 'x-grid-cell-topic', 
     text: "Topic", 
     dataIndex: 'title', 
     flex: 1, 
     //renderer: renderTopic, 
     sortable: false 
    },{ 
     text: "Author", 
     dataIndex: 'username', 
     width: 100, 
     hidden: true, 
     sortable: false 
    },{ 
     text: "Replies", 
     dataIndex: 'replycount', 
     align: 'center', 
     width: 70, 
     sortable: false 
    },{ 
     id: 'last', 
     text: "Last Post", 
     dataIndex: 'lastpost', 
     width: 130, 
     renderer: Ext.util.Format.dateRenderer('n/j/Y g:i A'), 
     sortable: false 
    }], 
    renderTo: Ext.getBody() 
}); 

포인트 :

- 클릭 "loadGrid"button가 레코드를로드 여기

는 코드입니다.

- "검색"textfield에 텍스트를 추가하고 입력 한 텍스트로 제공되는 쿼리를 기반으로 그리드를 새로 고치려면 검색 버튼을 클릭하십시오.

sencha fiddle 안에 코드를 추가하고 (오른쪽 상단 selectfield에서 고전 테마를 선택) 실행할 수도 있습니다.

내가 도움이 되었기를 바랍니다.

+0

답변을 주셔서 감사합니다하지만 정확히 내가 콜백 함수로 작성 해야하는지. – David

+0

'callback' 함수는 추가 기능 (저장소가 실제로 새 레코드를로드 할 때보기에서 수행 할 작업)을위한 것입니다. 예를 들어 store.getTotalCount()). 'loadData'를 사용하여 뷰에 직접 데이터를로드 할 필요가 없으며,'store.load'가 자동으로 뷰를 수행합니다. –

+0

나는 내 대답을 예제로 업데이트했다. –

관련 문제