1

枪 0.8.9,Node.js 到 Node.js

我需要完全删除一个节点,不留下任何痕迹,而不仅仅是删除它的属性。

我该怎么做?

试图打开一个父节点并删除其子节点但进入死循环并不断收到以下消息:

dinos in park { velociraptor: { statistics: { force: 9, speed: 15 } },
  trex: { statistics: { force: 25, speed: 5 } } }
dinos in park { velociraptor: { statistics: { force: 9, speed: 15 } },
  trex: { statistics: { force: 25, speed: 5 } } }
...

源代码:

const Gun = require('gun');
require('gun/lib/open');

const gun = new Gun();
const park = gun.get('park');

const velociraptor = park.get('velociraptor').put({
  statistics: {
    force: 9,
    speed: 15
  }
});

const trex = park.get('trex').put({
  statistics: {
    force: 25,
    speed: 5
  }
});

park.open(function (dinos) {
  console.log('dinos in park', dinos);
  delete dinos.trex;

  park.put(dinos, function (ack) {
    if (ack.err) {
      console.log(ack.error);
    }

    park.open(function (dinos) {
      console.log('dinos after trex deleted', dinos);
    });
  });
});

setTimeout(function () {
  park.open(function (dinos) {
    console.log('dinos after trex deleted', dinos);
  });
}, 20000);
4

0 回答 0