[gnome-maps/wip/mlundblad/transit-plugin-opendatach: 3/4] http: Add a parameter to use array notation
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/transit-plugin-opendatach: 3/4] http: Add a parameter to use array notation
- Date: Tue, 12 Nov 2019 22:00:38 +0000 (UTC)
commit 1e440974bb19d87f7acae61512963ea924e22be5
Author: Marcus Lundblad <ml update uu se>
Date: Thu Nov 7 22:33:08 2019 +0100
http: Add a parameter to use array notation
Add an optional parameter to toString()
for using array notation (adding [] to keys
with mulitple occurancies).
src/http.js | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/src/http.js b/src/http.js
index e90b61de..8d853fee 100644
--- a/src/http.js
+++ b/src/http.js
@@ -50,11 +50,19 @@ var Query = class Query {
this._query[key].push(value);
}
- toString() {
+ /**
+ * Get the query parameters in string form.
+ * If useArrayNotation is given, and true, use array notation adding []
+ * after key if there's multiple values for that key.
+ */
+ toString(useArrayNotation = false) {
let vars = [];
for(let key in this._query) {
let values = this._query[key];
- let encKey = encode(key);
+ let multipleValues = values.length > 1;
+ let encKey = encode(key) + (multipleValues && useArrayNotation ?
+ '[]' : '');
+
values.forEach(function(value) {
let encValue = encode(value);
if(encValue !== null)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]