【发布时间】:2019-07-23 11:05:15
【问题描述】:
我可以在对象“addable:”中实现一个承诺。保存新客户端后,添加到 slimselect 的 id 需要等待新的 _id。 谢谢
支付至*var Datastore = require('nedb');
var dclipro = new Datastore({filename: '/data/clipro.db', autoload: true});
var selectclipro = new SlimSelect({
select: '#bcofid_clipro',
valuesUseText: false,
addable: function (value) {
var newid = "";
var agrabar = {
name: value,
last_idcuenta: "null",
email: "notdefined@gmail.com",
memo: "not available",
auditlog: moment().format('MMMM Do YYYY, h:mm:ss a')
}
dclipro.update({name: value}, agrabar, options, function (err, numReplaced, upsert) {
if (err) {
console.error(err);
}
newid = upsert._id;
})
iziToast.show({
title: 'Bank',
message: 'New Payee has been saved successfully',
position: 'topRight'
});
return { text: value, value: newid }
},
onChange: (info) => {
console.log('elegido : value ' +info.value);
console.log('elegido : text ' +info.text);
}
})
【问题讨论】:
-
那么承诺在哪里?您是如何尝试使用的?
-
很难解析出你在这里问什么。看起来您需要
addable才能返回对象{text: value, value: newid}。如果你不能从addable返回一个 Promise,那将解决这个问题,那么不确定你是否可以,dclipro.update()是你的异步请求(我猜)。由于代码现在可以工作,iziToast.show()和返回都会在您的异步请求仍在触发时发生。在您确认没有错误之前,您不会希望显示成功(因此在update回调中),并且您不能返回您没有的东西。
标签: javascript node.js promise