将表与文件保存

发布于 2025-02-07 09:57:28 字数 1847 浏览 0 评论 0原文

我正在进行适合某些条件的搜索,例如特殊年份。我正在使用mongoDB,express.js和node.js。这是我的代码:

***table.ejs***
    <%yearOfsyllabusList.forEach(syllabus => {%>
      <div class="container fixTable">
        <main>
          <div class="row ">
            <table class="table" border="2">
              <div class="row">
              <thead class="table-primary">
                <tr>
                  <th scope="col">Year</th>
                  <th scope="col">Name</th>
                  <th scope="col">Additional info</th>
                </tr>
              </thead>
              <tbody>
                  <tr class="table-info">
                    <!-- <th scope="row">1</th> -->
                    <td><%= syllabus.yearOfsyl %></td>
                    <td><%= syllabus.nameOfsyl %></td>
                    <td><%= syllabus.syllabusInfo %></td>
                  </tr>
                </tbody>
                </div>
              </table>
            </div>
          </main>
    </div>
<%})%>

在这里,我确实使用教学大纲架构进行搜索,然后在表中显示结果(Table.ejs upper)。

function getSyllabusesYear(req, res, next){
  Syllabus.find({}, function(err, yearsOfsyllabus){
    if (err) throw err;
     res.locals.yearsOfsyllabusList = [];
     next();
  })
}

function postSyllabusesYear(req, res, next){
  const Year = req.body.yearCheck;
  Syllabus.find({
    yearOfsyl: Year
  }, function(err, yearsOfsyllabus){
    if (err) next(err);
     res.locals.yearsOfsyllabusList = yearsOfsyllabus;
     next();
  });
}

我想保存在表中收到的数据。我一直在通过互联网寻找任何信息,但我找不到适当的答案。也许,我应该尝试使用FS或类似的东西。您能给我任何建议或一些建议或对我的代码的一些修改吗?

I'm doing search which suits some conditions, for example special year. I'm using MongoDB, Express.js and Node.js. Here is a bit of my code:

***table.ejs***
    <%yearOfsyllabusList.forEach(syllabus => {%>
      <div class="container fixTable">
        <main>
          <div class="row ">
            <table class="table" border="2">
              <div class="row">
              <thead class="table-primary">
                <tr>
                  <th scope="col">Year</th>
                  <th scope="col">Name</th>
                  <th scope="col">Additional info</th>
                </tr>
              </thead>
              <tbody>
                  <tr class="table-info">
                    <!-- <th scope="row">1</th> -->
                    <td><%= syllabus.yearOfsyl %></td>
                    <td><%= syllabus.nameOfsyl %></td>
                    <td><%= syllabus.syllabusInfo %></td>
                  </tr>
                </tbody>
                </div>
              </table>
            </div>
          </main>
    </div>
<%})%>

Here I do search using my Syllabus schema and then I display results in table(table.ejs upper).

function getSyllabusesYear(req, res, next){
  Syllabus.find({}, function(err, yearsOfsyllabus){
    if (err) throw err;
     res.locals.yearsOfsyllabusList = [];
     next();
  })
}

function postSyllabusesYear(req, res, next){
  const Year = req.body.yearCheck;
  Syllabus.find({
    yearOfsyl: Year
  }, function(err, yearsOfsyllabus){
    if (err) next(err);
     res.locals.yearsOfsyllabusList = yearsOfsyllabus;
     next();
  });
}

I want to save data which I receive in table to file. I was looking for any information over the Internet, but I don't find the appropriate answer. Maybe, I should try using fs or something like that. Can you give me any suggestion or some piece of advice or maybe some modifications to my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文