如何完全删除节点?

时间:2017-11-07 17:02:45

标签: javascript node.js gun

枪0.8.9,Node.js-to-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);

0 个答案:

没有答案