0

我有一个玉模板,我有一个创建用户部分,可以将用户添加到 orchestrate.io 数据库。在其下方,我有一个包含删除和更新链接的所有用户的列表。当它到达服务器时,通过将密钥作为 res.params.id 通过 URL 传递,删除工作正常。当我使用密钥更新时,它看不到输入字段中的新值,因此我没有得到在服务器端使用的有效负载值。如何更新此字段?这是我的代码:服务器端 -

server.route({
   method: 'GET', 
   path: '/update/{id}',
   handler: function(req, reply){
       db.put('users', req.params.id, {
        "name": 'name',
        "password": 'password',
        "email": 'email'
      })
      .then(function (result) {
          reply.redirect('/');
      })
      .fail(function (err) {
          reply('no update');
      });
   }
});

翡翠模板-

doctype html
html
  head
    title Last October Weekly Challenge
  body
    div.container
      p This is the main user page. You can create, update, delete and view users.
      form(action='/',method='POST')
        label(for='name') Name
          input(id='name',type='text',value='',placeholder='Enter Name',name='name')
        label(for='password') Password
          input(id='password',type='password',value='',placeholder='Enter Password',name='password')
        label(for='email') Email
          input(id='email',type='email',value='',placeholder='Enter Email',name='email')
        input(id='submit',type='submit',value='Create User',name='submit')
      p Here are the current users:
      table
        each item in items
          tr
            td
              input(type='text' name='update-name' value= item.value.name)
            td
              input(type='text' name='update-password' value= item.value.password)
            td
              input(type='email' name='update-email' value= item.value.email)
            td
              a(href="/delete/" + item.path.key) Delete
            td
              a(href="/update/" + item.path.key) Update

感谢您的帮助。

4

1 回答 1

0

我看到了一些可能导致您的问题的事情。1)您的 server.route 方法是“GET”,但它应该是“POST”来处理/匹配表单的方法属性;并且,2) 您没有将 ID 作为表单中的隐藏字段(或作为操作 URL 的一部分,例如 form action="/update/12345" method="POST"...)。

于 2014-11-05T03:41:13.850 回答