Romain Romain - 7 months ago 9
Javascript Question

Update one item with localforage

I've a local indexeddb like this:

// Unlike localStorage, you can store non-strings.
localforage.setItem('123456', {
//0 - Ref cli
ref_cli: '4720271',
//1 - Offre client
offre_cli: 'Offre 3',
//2 - Date RDV
date_rdv: '22/09/2015',
//3 - Heure rdv
heure_rdv: '10H00',
//4 - Nom client
nom_cli: 'DURAND',
//5 - Prénom client
pren_cli: 'Pierre',
//6 -Adresse client
adr_cli: '3 rue de l\'église',
//7 - CP client
cp_cli: '75000',
//8 - Ville client
ville_cli: 'PARIS',
//9 - Batiment
bat_cli: 'A',
//10 - Escalier
esc_cli: '2',
//11 - Etage
etg_cli: '3'
}, function(err, value) { });


I want to update one item of this array. Eg:


offre_cli: 'offre 3' -> offre_cli: 'offre 4'


I've tried the code below, but it erases the previously array.:

localforage.setItem('123456', {offre_cli: 'offre 4'};


It's possible to update a single item, without update all array?

Answer

We find solution :). Thanks Buzinas for inspiration

  localforage.getItem('123456').then(function ( item ){
    item.offre_cli = 'offre 12';

    localforage.setItem('123456', item);

  });