Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

306
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda