javascript - Javascript 和 Express 出现奇怪的 If/Else 问题
问题描述
我在检查对象是否未定义时遇到问题。奇怪的是,这个错误在 Mac OSX 中不会发生,但在 Windows 上我得到一个“无法读取 to_char 的属性”错误。希望各位大侠能帮帮我!
这是代码:
let accountInfo = {};
let recentForms = {}
db.tx(async (t) => {
accountInfo = await t.one(
"SELECT * from useraccount INNER JOIN company on useraccount.company_id = company.id WHERE username = $1",
[req.params.username]
);
recentForms = await t.any(
"SELECT f.form_id, TO_CHAR(f.date_submitted :: DATE,'yyyy-mm-dd'), f2.form_name from formresponse f INNER JOIN forms f2 on f.form_id = f2.form_id WHERE f.company_id = $1",
[accountInfo.company_id]
);
return accountInfo, recentForms;
})
.then((data) => {
// We need to compare the form submitted date to our date today to determine if completed.
// First we need to see if to_char exists and then decalre the forms date as a date variable
if (recentForms[0].to_char !== undefined){
formDate = new Date(recentForms[0].to_char);
}
else{
formDate = '2120-01-12'
}
基本上,如果pg-promise 为recentForms[0].to_char 返回一些东西,我想把它变成一个javascript 日期变量。如果什么都没有,我想将 formDate 设置为远在未来的变量。不过,至少在 Windows 上,我无法让程序执行该 if 语句。
感谢任何帮助!
解决方案
推荐阅读
- java - 我想在Java中通过rexgs在=之后提取字符串
- android - 根据节点日期查询 Firebase 数据
- aws-lambda - 如何让我的 AWS Lambda 函数中的 fabric8 k8s 客户端使用 EKS 正确进行身份验证?
- javascript - javascript中的异步函数不起作用
- ios - 导航栏在标签视图中转到另一个标签时不显示
- ruby-on-rails - 使用 CookieStore 在多个 Rails 微服务之间共享会话
- javascript - 将静态数据范围移动到另一个工作表,同时将其他字段放入目标旁边的列中(Google 表格)
- python - 按条件删除前面的行
- delphi - Delphi $E 指令
- python - 数据框 pandas 中的几个 � 字符