简体   繁体   English

使用javascript动态生成的百里香叶输入并将其值发送到控制器不起作用

[英]dynamically generated thymeleaf input with javascript and send its value to the controller is not working

I have a table with rows with th:fields, everything works OK. 我有一张桌子,上面有带th:fields的行,一切正常。
I need to add new rows, so I did it with javascript but when I submit the form those new rows are not submited. 我需要添加新行,因此我使用javascript做到了,但是当我提交表单时,这些新行都没有提交。 Do I need a special magic for that? 我需要特殊的魔法吗?

th:field="*{configuredProperties[__${iterator.index}__].propertyType}"

Thanks! 谢谢!

edited: I create a row like this: 编辑:我创建这样的行:

function addProperty() {
        var rows = $('#propertiesTable tbody tr');
        var row = rows[0];
        var clone = row.cloneNode(true);

        clone.getElementsByTagName('input')[0].value = null;
        clone.getElementsByTagName('input')[1].value = null;
        clone.getElementsByTagName('input')[2].value = null;

        var lastRow = rows[rows.length - 1];
        var newId = parseInt(lastRow.getAttribute("id")) + 1;
        clone.id = newId;

        var link = $(clone).find('#removeProperty')[0];
        link.setAttribute('onclick', 'removeProperty(' + newId + ')');


        var propertyType = $(clone).find('#propertyType')[0];
        propertyType.setAttribute('name', '*{configuredProperties[' + newId + '].propertyType');
        var propertyName = $(clone).find('#propertyName')[0];
        propertyName.setAttribute('name', '*{configuredProperties[' + newId + '].propertyName');
        var defaultValue = $(clone).find('#defaultValue')[0];
        defaultValue.setAttribute('name', '*{configuredProperties[' + newId + '].defaultValue');    

        var tbody = $('#propertiesTable tbody')[0];
        tbody.appendChild(clone);
}

in this block you need to provide the name of your bean field 在此块中,您需要提供bean字段的名称

   var propertyType = $(clone).find('#propertyType')[0];
    propertyType.setAttribute('name', '*{configuredProperties[' + newId + '].propertyType');
    var propertyName = $(clone).find('#propertyName')[0];
    propertyName.setAttribute('name', '*{configuredProperties[' + newId + '].propertyName');
    var defaultValue = $(clone).find('#defaultValue')[0];
    defaultValue.setAttribute('name', '*{configuredProperties[' + newId + '].defaultValue'); 

by constructing the field like so 通过像这样构建领域

   var propertyType = $(clone).find('#propertyType')[0];
    propertyType.setAttribute('name', 'configuredProperties[' + newId + '].propertyType');
    var propertyName = $(clone).find('#propertyName')[0];
    propertyName.setAttribute('name', 'configuredProperties[' + newId + '].propertyName');
    var defaultValue = $(clone).find('#defaultValue')[0];
    defaultValue.setAttribute('name', 'configuredProperties[' + newId + '].defaultValue');  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM