2010-12-08 2 views
3

다음과 같은 저장소 구성으로 Grid 구성 요소를 만들었습니다.Extjs Restful Store, Batch에서 요청을 보내시겠습니까?

 //Create the store 
    config.store = new Ext.data.Store({ 
     restful: true, 
     autoSave: false, 
     batch: true, 
     writer: new Ext.data.JsonWriter({ 
      encode: false 
     }), 
     reader: new Ext.data.JsonReader({ 
      totalProperty: 'total', 
      root: 'data', 
      fields: cfg.fields 
     }), 
     proxy: new Ext.data.HttpProxy({ 
      url:cfg.rest, 
      listeners:{ 
       exception: { 
        fn: function(proxy, type, action, options, response, arg) { 
         this.fireEvent('exception', proxy, type, action, options, response, arg); 
        }, 
        scope: this 
       } 
      } 
     }), 
     remoteSort: true, 
     successProperty: 'success', 
     baseParams: { 
      start: 0, 
      limit: cfg.pageSize || 15 
     }, 
     autoLoad: true, 
     listeners: { 
      load: { 
       fn: function() { 
        this.el.unmask(); 
       }, 
       scope: this 
      }, 

      beforeload: { 
       fn: function() { 
        this.el.mask("Working"); 
       }, 
       scope: this 
      }, 
      save: { 
       fn: function(store, batch, data) { 
        this.el.unmask(); 
        this.fireEvent('save', store, batch, data); 
       }, 
       scope: this 
      }, 

      beforewrite: { 
       fn: function(){ 
        this.el.mask("Working..."); 
       }, 
       scope: this 
      } 

     } 
    }); 

참고 : fireEvents를 무시하십시오. 이 저장소는 공유 사용자 지정 그리드 구성 요소에서 구성됩니다.

그러나 여기서 한 가지 문제가 있습니다. 내가 한 CRUD 작업이 무엇이든, 항상 선택한 N 개의 행과 동일한 N 개의 요청을 서버에 제공합니다. 즉, 10 개의 행을 선택하고 Delete 키를 누르면 10 개의 DELETE 요청이 서버에 전송됩니다.

예를 들어, 다음과 같이 레코드를 삭제하는 방법입니다.

/** 
* Call this to delete selected items. No confirmation needed 
*/ 
_deleteSelectedItems: function() { 
    var selections = this.getSelectionModel().getSelections(); 
    if (selections.length > 0) { 
     this.store.remove(selections); 
    } 
    this.store.save(); 
    this.store.reload(); 
}, 

참고 : "this"의 범위는 Grid Component입니다.

그래서, 그렇게 될까요? 또는 구성 문제가 있습니까? Extjs 3.3.1을 사용 중이며 Ext.data.Store,

아래의 batch 설명서에 따라 Store가 RESTful이면 DataProxy도 RESTful이며 각 레코드에 대해 고유 트랜잭션이 생성됩니다. .

이것이 나의 구성 문제가되기를 바랍니다.

참고 : listful, encode, writeAllFields, encodeDelete에서 Ext.data.JsonWriter를 시도했습니다 ... 희망 없음

답변

2

당신은 정확하게 문서를 읽을 수없는 희망 ... Ext.data.JsonWriter에, writeAllFields, encode, listfulencodeDelete을 시도; 그것은 그렇게 작동해야합니다. 그리드에 RESTful 스토어를 사용할 것인지 여부를 선택할 때마다 고려해야 할 사항입니다. 배치 작업이 필요할 경우 RESTful 상점은 친구가 아닙니다. 죄송합니다. 이 배치되지 왜 궁금 할 그냥 사람들을 위해

+0

안녕하세요, 귀하의 답변에 많은 감사드립니다. 이것이 내가 적어도이 문제를 제기 한 구성 실수 중 하나라고 생각했습니다. 적어도 당신은 나와 확인해주었습니다. –

+0

이것이 여전히 ExtJS 4.1.3에서 사실인지 궁금합니다. – justinzane

+0

@justinzane - ExtJS 4에 대해 모르겠습니다.이 질문은 ExtJS 3에 관한 것입니다. v4 안정적인 일괄 요청에 대해 물어 보는 것은 가치가 있습니다. – wes

6

: 언급 된 문서에 대해서는

,

스토어 편안하고 경우, DataProxy도 편안하고 있으며, 고유의 트랜잭션이 각각 생성된다 기록. @constructor

// If Store is RESTful, so too is the DataProxy 
if (this.restful === true && this.proxy) { 
    // When operating RESTfully, a unique transaction is generated for each record. 
    // TODO might want to allow implemention of faux REST where batch is possible using RESTful routes only. 
    this.batch = false; 
    Ext.data.Api.restify(this.proxy); 
} 

에서 당신이 /src/data/Store.js

라인 (309)에 Ext.data.Store의 소스 코드에 보면 참

, 내가 restful를 사용할 때 실현 왜 그렇게이다, 내 batch 절대로 true으로 변경되지 않습니다.

+1

우수 답변! 내 POV에서 성가신 것을 완전히 fscking,하지만 그건 네 잘못이 아니야.나는 Sencha가 나머지가 RESTful 트랜잭션 당 하나의 xmlhttprequest를 필요로한다고 생각하는지 궁금하다. 일괄 처리는 상태 일치의 전제를 변경하지 않는 것처럼 보입니다. – justinzane

+0

와우 감사합니다. 그러나 이것은 좀 오래된 것입니다 (2010)! 이 기능은 기존 v4.1에도 계속 적용됩니까? 롤렉스! –

관련 문제