根据下拉列表中的currentYear值更新表(外部数据)

时间:2019-09-10 09:33:15

标签: google-app-maker

我有一个表,显示员工的休假请求。现在,我正在使用“ onAttach”事件在该表中显示所有年份的请求。我想通过绑定到外部sql数据中的“ year”列来实现下拉菜单。因此,每当我从下拉列表中选择年份时,我都希望表格进行更新,仅在表格中显示该特定年份的请求。我该如何实施?

表的onAttach函数loadHolidayTable()导致该客户端函数

function loadHolidayTable() {
  app.datasources.HolidayModel.load({
    failure: function (error) {
      displayTimedSnackbar('Unable to load holidays table: ' + error);
    }
  });
}

数据源“ HolidayModel”中的“我的服务器脚本”

return calculateHolidayModel(query);

导致此服务器功能:

function calculateHolidayModel(query) {
  var queryStr = '';
  var currentYear = null; --> to be replaced by dropdown value

  if (currentYear === null || currentYear == 'undefined') {
    queryStr = 'SELECT * FROM Holidays WHERE employeeID = ' + "'" + empID + "'";
  }
  else {
    queryStr = 'SELECT * FROM Holidays WHERE employeeID = ' + "'" + empID + "'" + ' AND year = ' + "'" + currentYear + "'";
  }

  console.log(queryStr);

  //var dayRecords = [];
  var holidayRecords = [];
  var connection = getJDBCConnection_();
  var statement = connection.prepareStatement(queryStr);

  try {
    var results = statement.executeQuery();

    while(results.next()) {
      var holidayRecord = app.models.HolidayModel.newRecord();
      holidayRecord.ID = results.getInt(2);
      holidayRecord.From = new Date(results.getString(3));
      holidayRecord.To = new Date(results.getString(4));
      holidayRecord.Status = results.getString(5);
      holidayRecords.push(holidayRecord);
      console.log(results.getInt(2));
    }
    results.close();
    statement.close();
  } catch (err) {
    console.log(err);
  }

  return holidayRecords;
}

currentYear应该替换为下拉菜单中的值。

欢迎任何建议!

0 个答案:

没有答案