Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

305
Visualizações
ExtJS - How do I pass ID when syncing store?

On ExtJS 6.2, I'm getting data from database like this: myStore.load({id: myId);.

How do I pass the ID while syncing? This doesn't work: myStore.sync({id: myId);

I'm using a REST proxy and my URL is in this format: mydomain/users/1

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can simply use myStore.sync(), you don't need to specify id. The sync function will examine the store contents, and add/delete/update records as needed.

When using REST, you can set writeRecordId of Ext.data.write.Writer (see here) to false, since with REST id is usually appended to the URL, as in your case.

about 4 years ago · Juan Pablo Isaza Relatório

0

I solved by extending Ext.data.proxy.Rest and overriding the buildUrl method to be able to extract the ID from the request parameters. Then I used this overridden proxy in my model:

Ext.define('MYPROJ.proxy.Settings', {
   extend : 'Ext.data.proxy.Rest',
   alias  : 'proxy.settings',
   buildUrl(request) {
      const url = this.callParent([request]);
      const id  = request.getParams().id;

      if (id) {
         delete request.getParams().id;

         const proxyUrl = request.getProxy().getUrl();

         return url.replace(proxyUrl, `${proxyUrl}/${id}`);
      }

      return url;
   }
});

Ext.define('MYPROJ.model.Setting', {
   extend  : 'Ext.data.Model',
   alias   : 'model.setting',

   clientIdProperty: 'clientId',

   fields: [{
      name    : 'id',
      type    : 'int',
      persist : false
   }, {
      name   : 'name',
      type   : 'string',
      unique : true
   }],

   proxy: {
      type : 'settings', // <- Use overridden proxy here
      url  : `/something/settings`
   }
});

Then in my code I can use sync() like this:

const myID = 10;

this.settingsStore.load({id: myID});

//...

this.settingsStore.sync({params: {id: myID}});

When sync() is called myID will be extracted from params on MYPROJ.proxy.Settings and added to the URL (/something/settings/10).

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda