Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript req.body在20个条目后自动将数组强制转换为对象_Javascript_Node.js_Express - Fatal编程技术网

Javascript req.body在20个条目后自动将数组强制转换为对象

Javascript req.body在20个条目后自动将数组强制转换为对象,javascript,node.js,express,Javascript,Node.js,Express,在我的表单中,我可以动态添加任意数量的属性: <form action=""> <div class="property"> <label>Name : <input type="text" name="properties[1][name]"></label> <label>Order : <input type="text" name="properties[1][order]"><

在我的表单中,我可以动态添加任意数量的属性:

<form action="">
  <div class="property">
    <label>Name : <input type="text" name="properties[1][name]"></label>
    <label>Order : <input type="text" name="properties[1][order]"></label>
    <label>Label : <input type="text" name="properties[1][label]"></label>
    <label>Type : <input type="text" name="properties[1][type]"></label>
    <label>Description : <textarea name="properties[1][description]"></textarea></label>
  </div>
  <div class="property">
    <label>Name : <input type="text" name="properties[2][name]"></label>
    <label>Order : <input type="text" name="properties[2][order]"></label>
    <label>Label : <input type="text" name="properties[2][label]"></label>
    <label>Type : <input type="text" name="properties[2][type]"></label>
    <label>Description : <textarea name="properties[2][description]"></textarea></label>
  </div>
  <div class="property">
    <label>Name : <input type="text" name="properties[3][name]"></label>
    <label>Order : <input type="text" name="properties[3][order]"></label>
    <label>Label : <input type="text" name="properties[3][label]"></label>
    <label>Type : <input type="text" name="properties[3][type]"></label>
    <label>Description : <textarea name="properties[3][description]"></textarea></label>
  </div>
  ...
</form>
以下是20个或更少属性的结果:

isArray : true
isObject : true
properties : [ { name: 'test 1',
    order: '1',
    label: 'label 1',
    type: 'type 1' },
  { name: 'test 2',
    order: '2',
    label: 'label 2',
    type: 'type 2' },
....
  { name: 'test 20',
    order: '20',
    label: 'label 20',
    type: 'type 20' } ]
拥有20多处房产:

isArray : false
isObject : true
properties : { '1' :
  { name: 'test 1',
    order: '1',
    label: 'label 1',
    type: 'type 1' },
  '2' :
  { name: 'test 2',
    order: '2',
    label: 'label 2',
    type: 'type 2' },
....
  '21' :
  { name: 'test 21',
    order: '21',
    label: 'label 21',
    type: 'type 21' } }
我想了解node.js为什么会有这种行为,以及如何避免这种行为。 有人能帮我吗

PS:我不得不减少我的代码示例,因为stackoverflow不喜欢代码多于解释。希望这仍然可以理解。

正文解析器(处理请求正文)使用库解析URL编码的数据

该库的状态为“关于阵列”:

qs还将限制在数组中指定索引的最大索引为20。任何索引大于20的数组成员都将转换为索引为键的对象

通过传递
arrayLimit
选项可以覆盖此限制

然而,似乎没有办法通过
主体解析器将该选项传递给
qs
。但将对象转换为数组相对容易:

post.properties.length = Object.keys(post.properties).length;
let properties = Array.from(post.properties);
正文解析器
(处理请求正文)使用库解析URL编码的数据

该库的状态为“关于阵列”:

qs还将限制在数组中指定索引的最大索引为20。任何索引大于20的数组成员都将转换为索引为键的对象

通过传递
arrayLimit
选项可以覆盖此限制

然而,似乎没有办法通过
主体解析器将该选项传递给
qs
。但将对象转换为数组相对容易:

post.properties.length = Object.keys(post.properties).length;
let properties = Array.from(post.properties);

我已经把它改了,但我不明白它为什么会这样做,这让我很恼火。我也不知道数组。从。也谢谢你。我已经转换了它,但不明白它为什么会这样做让我很恼火。我也不知道数组。从。也谢谢你。