Reactnative 上的 Promise
我写了一个在 sqlite 中插入数据的承诺:
var promise_insertData=new Promise(function(resolve, reject){
db.transaction((tx) =>{
tx.executeSql('INSERT INTO chontact (recordID,user, phone) VALUES (?,?,?)',[recordID, name, number],
(tx, results) => {
var status=(results.rowsAffected > 0) ? true : false;
if(status)
resolve()
else
reject()
}
);
});
reject()
})
当我尝试插入数据时出现错误
promise_insertData(db,recordid,name,phone).then(function(result){
Toast.show('ok...');
del_item();
}).catch(function(error){
Toast.show('error');
})
错误:
TypeError: (0, _$$_REQUIRE(_dependencyMap[12], "./JSfiles/functions").promise_insertData) is not a function. (In '(0, _$$_REQUIRE(_dependencyMap[12], "./JSfiles/functions").promise_insertData)(db, recordid, textinput, textinputphone)', '(0, _$$_REQUIRE(_dependencyMap[12], "./JSfiles/functions").promise_insertData)' is an instance of Promise)
I write a promise to insert data in sqlite:
var promise_insertData=new Promise(function(resolve, reject){
db.transaction((tx) =>{
tx.executeSql('INSERT INTO chontact (recordID,user, phone) VALUES (?,?,?)',[recordID, name, number],
(tx, results) => {
var status=(results.rowsAffected > 0) ? true : false;
if(status)
resolve()
else
reject()
}
);
});
reject()
})
when I try to insert data I got error
promise_insertData(db,recordid,name,phone).then(function(result){
Toast.show('ok...');
del_item();
}).catch(function(error){
Toast.show('error');
})
Error:
TypeError: (0, _$_REQUIRE(_dependencyMap[12], "./JSfiles/functions").promise_insertData) is not a function. (In '(0, _$_REQUIRE(_dependencyMap[12], "./JSfiles/functions").promise_insertData)(db, recordid, textinput, textinputphone)', '(0, _$_REQUIRE(_dependencyMap[12], "./JSfiles/functions").promise_insertData)' is an instance of Promise)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下。您应该能够
promise_insertData(stuff).then(doSomethingElse)
我不确定代码中的最终reject()
,这可能是错误的。Give this a try. You should be able to
promise_insertData(stuff).then(doSomethingElse)
I'm not sure about the finalreject()
in your code, that might be wrong.