使用语言获取数组值Multipart / form-data

时间:2017-02-20 04:45:12

标签: javascript node.js forms

包含数组的多部分/表单数据---------- // ---------------------

我无法获得值“fields.c”。

*---------------html form
<form action="/companyInfo" method="post" enctype="multipart/form-data">
<input type="text" name='txtCompanyPhone' value='0909 234 456' />
<input type="text" name='txtCompanyName[vi]' value='Namevi' />
<input type="text" name='txtCompanyName[en]' value='Nameen' />
<input type="text" name='txtCompanyName[ja]' value='Nameja' />
</form>

*---------------controller "companyInfo"
var form = new multiparty.Form();
form.parse(req, function(err, fields, files) {
        console.log(fields);
        //result
        // txtCompanyPhone: ['0909 234 456'],
        // ,'txtCompanyName[vi]': ['Namevi'],
        // ,'txtCompanyName[en]': ['Nameen'],
        // ,'txtCompanyName[ja]': ['Nameja'],

        console.log(fields.txtCompanyPhone);
        result------ ['0909 234 456']

        console.log(fields.txtCompanyName[vi]);
        //result ----- error

        var c = 'txtCompanyName[vi]';
        console.log(fields.c);
        //result ------undefined

        //----------Help me show results-----------------            
}

如何以此形式获取值“fields.c”或“fields.txtCompanyName [vi]”?

2 个答案:

答案 0 :(得分:1)

尝试fields['txtCompanyName']['vi']

答案 1 :(得分:0)

您需要fields['txtCompanyName[vi]']