您可以使用remove method來做到這一點。 例如,如果使用:screen.append(form);
將表單(以屏幕作爲父級)附加到屏幕上,則可以使用screen.remove(form);
銷燬該表單,它可以很好地工作。
實施例:
var form = blessed.form({
parent: screen,
width: '50%',
height: 7,
border: {
type: 'line'
},
keys: true,
tags: true,
top: 'center',
left: 'center'
});
var cancel = blessed.button({
parent: form,
mouse: true,
keys: true,
shrink: true,
padding: {
left: 1,
right: 1
},
left: 48,
width: 9,
top: 3,
name: 'cancel',
content: 'cancel',
style: {
focus: {
bg: 'blue',
fg: 'white'
},
hover: {
bg: 'blue',
fg: 'white'
}
},
border: {
type: 'line'
}
});
var submit = blessed.button({
parent: form,
mouse: true,
keys: true,
shrink: true,
padding: {
left: 1,
right: 1
},
left: 35,
width: 9,
top: 3,
name: 'submit',
content: 'submit',
style: {
focus: {
bg: 'blue',
fg: 'white'
},
hover: {
bg: 'blue',
fg: 'white'
}
},
border: {
type: 'line'
}
});
screen.append(form);
submit.focus();
screen.render();
cancel.on('press', function() {
screen.remove(form);
screen.render();
});