ljharb / qs

A querystring parser with nesting support
BSD 3-Clause "New" or "Revised" License
8.54k stars 728 forks source link

How to implement such parsing #445

Closed zizhuxuaner closed 2 years ago

zizhuxuaner commented 2 years ago

{ a: [], b:{ c: [], }, e: '111' } =====> a=&b[c]=&e=111

How to implement such parsing

ljharb commented 2 years ago

Why would you want that? a and b[c] are both empty arrays, so there's nothing there to serialize. a= and b[c]= mean something different.

zizhuxuaner commented 2 years ago

你为什么要那个?a 和 b[c] 都是空数组,所以没有什么可以序列化的。a=b[c]=意味着不同的东西。

Can I keep fields? Because the backend needs these fields to determine what to submit. For example, I have a checkbox that allows you to select nothing, and the result is an empty array. demo:https://element.eleme.cn/#/zh-CN/component/checkbox

ljharb commented 2 years ago

The proper way to handle this with checkboxes on the web is a hidden input with the same name, placed in the HTML before the checkboxes, so that the backend makes a decision based on explicit input and never based implicitly on the lack of input.

zizhuxuaner commented 2 years ago

The proper way to handle this with checkboxes on the web is a hidden input with the same name, placed in the HTML before the checkboxes, so that the backend makes a decision based on explicit input and never based implicitly on the lack of input.

Thank you very much. I know what's wrong with me. Thank you