从HTML表中获取数据库项目的价值

时间:2018-10-03 20:43:30

标签: javascript html node.js express handlebars.js

我有一个表,用于存储用户名和猫鼬集合中的其他数据,并且我试图向该表中添加一个按钮单元格,在该单元格中,单击按钮时,该行要么变为可编辑状态,要么路由到新页面进行编辑。

最终结果并不重要,但是我很难获取表行的内容。任何帮助将不胜感激,我将在下面发布我的代码。

<h2 class="page-header">Fan Favourites</h2>
<h2>{{log}}</h2>
<p>Below are the People you have Selected to be your Favourites</p>



<!-- OLD TABLE EMPTY NO DATA -->

<!-- <table style="width:100%" border="1">
  <tr>
    <th>Username</th>
    <th>Voting Power</th>
    <th>Number Of Times</th>
    <th>Time to Wait</th>
    <th>Followers</th>
  </tr>
  <tr>
    <tr></tr>
    <tr></tr>
    <tr></tr>
    <tr></tr>
    <tr></tr>
  </tr>
</table> -->


<!-- OLD LIST NOT NEEDED-->

<!-- <ul>
{{#each favourites}}
    <li>@{{ username }}</li>
{{/each}}
</ul> -->

{{#if favourites}}
    <table style="width:100%" border="1">
      <tr>
        <th>Username</th>
        <th>Title 1</th>
        <th>Title 2</th>
        <th>Title 3</th>
        <th>Title 4</th>
        <th>Title 5</th>

      </tr>
        {{#each favourites}}
            <tr>
                <td>@{{username}}</td>
                <td>{{item1}}</td>
                <td>{{item2}}</td>
                <td>{{item3}}</td>
                <td>{{item4}}</td>
                <td><button class="editbtn">edit</button></td>

            </tr>
        {{/each}}
    </table>
{{else}}
    <h3>No users found!</h3>
{{/if}}



<form method="post" action="/adduser/adduser" id="adduserform">
  <div class="form-group">
    <label>Add Users Here</label>
    <input type="text" class="form-control" placeholder="Username" name="username">
  </div>
  <button type="submit" class="btn btn-default">Add User</button>
</form>

<form method="post" action="/adduser/adduser" id="adduserform">
  <div class="form-group">
    <label>Remove Users Here</label>
    <input type="text" class="form-control" placeholder="Username" name="username">
  </div>
  <button type="submit" class="btn btn-default">Add User</button>
</form>

这是路由页面,

    var express = require('express');
    var router = express.Router();
    const adduser = require('../models/adduser');
    const users = require('../routes/users');




    // Get Homepage
    router.get('/', ensureAuthenticated, function(req, res){
        // console.log("did it work");
        // console.log(req.body.log);
        // console.log("no");
        // console.log(res.locals.user);
        // console.log('not /test test');
        adduser.find({ownerUsername: res.locals.user.username}).then(function(results){
            res.render('index', {favourites: results});
            // res.json(results);
        })

    });

    function ensureAuthenticated(req, res, next){
        if(req.isAuthenticated()){
            return next();
        } else {
            //req.flash('error_msg','You are not logged in');
            res.redirect('/users/login');
        }
    }

    module.exports = router;

超级希望有人能帮助我,谢谢您的宝贵时间。

0 个答案:

没有答案