javascript - Update one item with localforage - Stack Overflow

I've a local indexeddb like this: Unlike localStorage, you can store non-strings.localforage.se

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?

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?

Share Improve this question edited Sep 24, 2015 at 21:37 Buzinas 11.7k2 gold badges38 silver badges59 bronze badges asked Sep 24, 2015 at 21:32 RomainRomain 1111 silver badge5 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

You can get the current object saved into localforage, update it, and save it back. E.g:

localforage.getItem('123456').then(function (item) {
  item.offre_cli = 'offre 4';
  localforage.setItem('123456', item );
});

We find solution :). Thanks Buzinas for inspiration

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

    localforage.setItem('123456', item);

  });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743698933a4492234.html

相关推荐

  • javascript - Update one item with localforage - Stack Overflow

    I've a local indexeddb like this: Unlike localStorage, you can store non-strings.localforage.se

    17小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信