为了使项目在vis.js中可编辑,它使用了SweetAlert可以使用的回调
我想使用SweetAlert2来利用它的新功能,但是它使用 Promise 而不是回调,而 vis.js 使用回调!
这是取自http://visjs.org/examples/timeline/editing/editingItemsCallbacks.html的示例代码:
第 47 到 57 行和第 129 到 137 行,其中 vis.js 调用 SweetAlert 进行提示:
onAdd: function (item, callback) {
prettyPrompt('Add item', 'Enter text content for new item:', item.content, function (value) {
if (value) {
item.content = value;
callback(item); // send back adjusted new item
}
else {
callback(null); // cancel item creation
}
});
},
function prettyPrompt(title, text, inputValue, callback) {
swal({
title: title,
text: text,
type: 'input',
showCancelButton: true,
inputValue: inputValue
}, callback);
}
那么如何修改它以使用 SweetAlert2 呢?