Node.js Jade模板-如何将数据从查看页面传递到编辑页面
我将express与jade一起使用,并为数据创建了一个表视图。当我点击编辑时,它应该在编辑页面的各个输入字段中显示数据(工厂、材料、货币等) 数据的表视图页Node.js Jade模板-如何将数据从查看页面传递到编辑页面,node.js,express,Node.js,Express,我将express与jade一起使用,并为数据创建了一个表视图。当我点击编辑时,它应该在编辑页面的各个输入字段中显示数据(工厂、材料、货币等) 数据的表视图页 extends layout block content h1(style='text-align:center')= title button(type='submit', onClick='nav()') Add a Material script. function nav() { window.l
extends layout
block content
h1(style='text-align:center')= title
button(type='submit', onClick='nav()') Add a Material
script.
function nav() {
window.location.href = '/addpage'
}
function passvalue(params) {
console.log(params)
}
br
br
-var product = data
div
table.table.table-hover(border='1', style='width:100%')
tr
th Plant
th Material
th Currency
th Rate
th Options
tbody
each value in product
tr
td(style='text-align:center')= value.PLANT
td(style='text-align:left')= value.MATERIAL
td(style='text-align:left')= value.CURRENCY
td(style='text-align:right')= value.RATE
td(style='text-align:left')
ul
a(href = '/',
onClick = `javascript:alert("Plant :${value.PLANT}, Material : ${value.MATERIAL}, Customer : ${value.CUSTOMER}, Rate : ${value.RATE}, Currency : ${value.CURRENCY}, Price_Unit : ${value.PRICE_UNIT}, Cond_Unit : ${value.COND_UNIT}, Portal_User : ${value.PORTAL_USER}")`
) View
br
a(href = '/editpage', onClick = `passvalue(${value})`) Edit
br
a(href = '/', onClick = 'javasript:alert("Delete functionality development is in-progress")') Delete
编辑页面以编辑所选数据
extends layout
block content
h1= title
label(for='plant') Plant:
input(placeholder = 'Plant Number', id = 'plant')
br
br
div
label(for='material') Material:
input(placeholder = 'Material Name')
br
br
div
label(for='customer') Customer:
input(placeholder = 'Customer Code')
br
br
div
label(for='rate') Rate:
input(placeholder = 'Rate')
br
br
div
label(for='currency') Currency:
input(placeholder = 'Currency')
br
br
div
label(for='price_unit') Price_Unit:
input(placeholder = 'Price_Unit')
br
br
div
label(for='cond_unit') Cond_Unit:
input(placeholder = 'Cond_Unit')
br
br
div
label(for='portal_user') Portal_User:
input(placeholder = 'Portal_User')
br
br
div
button(type='submit') Save
button(type='submit', onClick = 'nav()') Cancel
script.
function nav() {
window.location.href='/'
}
是您在这方面的许多良好起点之一
基本上,您需要为编辑页面设置一个路由,该路由将植物ID作为URL的一部分,然后使用它检索该植物的数据。将结果馈送到jade模板可以让它完成其工作:
app.get('/plant/:id', function(req, res){
// plant id is available here as req.params.id
if(req.params.id){
// fetch data for plant with this id
res.render('edit-plant', data);
} else {
// no id given, must be a new plant
res.render('edit-plant', {});
}
});
然后,在列表页面上,只需将plant id添加到链接的href标记:
each plant in plants
a(href= '/plants/' + plant.id)= plant.name