首页 > 解决方案 > 帕格,如果表格中的语句不提取数据

问题描述

我正在尝试在 pug 中动态创建一个表单。

form(method='POST' action=postRoute)
                        each component in step.components
                            .row
                                if (component.pug == 'name')
                                    input(type="text", name="title")
                                    include component/name
                                else if (component.pug == 'description')
                                    include component/description
                                else if (component.pug == 'thumbnail')
                                    include component/imageLoader
                                else if (component.pug == 'tag_field')
                                    include component/addTags
                                else if (component.pug == 'tag_equipment')
                                    include component/addEquipmentTags
                                else if (component.pug == 'plans')
                                    .add-plans-background-area
                                        .row
                                            a(href='#')
                                                .add-plan(onclick='addNewPlan()') +
                                        - for (var i = 0; i < 3; ++i)
                                            .row.plan-preview-in-create(onclick='previewPlan()')
                                                .col-md-1
                                                    img(src='https://www.healthline.com/hlcmsresource/images/bodybuilding-meal-plan-1296x728-feature.jpg').plan-thumbnail
                                                .col-md-10
                                                    .plan-name= 'Package name ' + i

                                                .col-md-1
                                                    .plan-exit
                                                        a(href='#' onclick='removePlanFromPackage()')
                                                            i.material-icons.menu-icon= 'close'


                                else
                                    p= component.pug

                        .row.buttons-group
                            - if (index == 0)
                                .col-md-2
                                    button(type="button" onclick=`nextInStepSectionDidClick('${stepIds}', '${index}')`).next-button-base.next-button-enable NEXT
                            - else if (index == (config.length - 1))
                                .col-md-2
                                    button(type="button" onclick=`backInStepSectionDidClick('${stepIds}', '${index}')`).back-button-base BACK
                                .col-md-2
                                    button.next-button-base.next-button(type='submit') SAVE
                            - else
                                .col-md-2
                                    button(type="button" onclick=`backInStepSectionDidClick('${stepIds}', '${index}')`).back-button-base BACK
                                .col-md-2
                                    button(type="button" onclick=`nextInStepSectionDidClick('${stepIds}', '${index}')`).next-button-base.next-button-enable NEXT

正如您所看到的,我有一个 for each 和一个配置文件,我正在动态创建表单。这将对我的项目有所帮助,因为我有很多相似的观点。

无论如何,当我提交表单时,我无法提取数据,但是当我在 if 语句上方添加一个输入时,我能够提取它。

// Get submited data
router.post('/', function (req, res) {
    console.log(req.body);
    res.send('Post page');
})

任何想法如何解决这个问题?

标签: javascriptpugjade4j

解决方案


推荐阅读