gpt4 book ai didi

javascript - Keystone JS View 上的事件不起作用

转载 作者:行者123 更新时间:2023-11-29 23:42:20 24 4
gpt4 key购买 nike

我正在使用 KeystoneJS 做一个电子商务网站(学习目的)。在我显示所有产品的 View 中,我想添加一个过滤器以按价格对项目进行排序,另一个过滤器仅显示一个品牌的产品。需要两份表格,但我不能只提交一份表格

我的 products.pug 看起来像这样

.container
form(method='post')
input(type='hidden', name='action', value='products')
button(type='submit').btn.btn-primary Send

我在 routes/views/中的 products.js 看起来像这样

[...]
// Print a word when submit the form
view.on('post', { action: 'products' }, function(next) {
console.log('POST')
next()
})
// Get all products from db
view.on('init'...)
// Render
view.render('products')

所以基本上我想做的是在我点击 View 中的按钮时打印POST。相反,我收到了一个 404 错误页面。如果你们能帮助我,我将不胜感激

最佳答案

明白了!在/routes/index.js 中我替换了

app.get('/products', route.views.products);

对于

app.all('/products', route.views.products);

我觉得自己很傻但是很开心。

关于javascript - Keystone JS View 上的事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44980574/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com