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 设置为远在未来的变量。不过,我无法让程序执行该 if 语句,至少在 Windows 上是这样。

感谢任何帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)