|
413 | 413 | return ''; |
414 | 414 | } |
415 | 415 | var pieces = []; |
416 | | - Object.keys(object).forEach(function(key) { |
417 | | - // TODO(rictic): handle array values here, in a consistent way with |
418 | | - // iron-ajax params. |
419 | | - pieces.push( |
420 | | - this._wwwFormUrlEncodePiece(key) + '=' + |
421 | | - this._wwwFormUrlEncodePiece(object[key])); |
422 | | - }, this); |
| 416 | + pieces = this._wwwFormUrlEncodeRecurrent(null, object , pieces); |
423 | 417 | return pieces.join('&'); |
424 | 418 | }, |
425 | | - |
| 419 | + /** |
| 420 | + * Funcion parse recurrently whole object. Support multi level nodes |
| 421 | + * |
| 422 | + * @param {String} keyprefix The prefix of key (parent name). |
| 423 | + * @param {Object} object The object (or part of it) to encode |
| 424 | + * as x-www-form-urlencoded. |
| 425 | + * @param {Array} container Array which contains all parsed elements. |
| 426 | + * @return {Array} array with parsed element |
| 427 | + */ |
| 428 | + _wwwFormUrlEncodeRecurrent: function(keyprefix, object, container) { |
| 429 | + if(!container){ |
| 430 | + container = []; |
| 431 | + } |
| 432 | + if(!object){ |
| 433 | + return container; |
| 434 | + } |
| 435 | + Object.keys(object).forEach(function(key) { |
| 436 | + var keyWithPrefix; |
| 437 | + if(!keyprefix){ |
| 438 | + keyWithPrefix = key; |
| 439 | + }else{ |
| 440 | + keyWithPrefix = keyprefix + '[' + key + ']'; |
| 441 | + } |
| 442 | + if((Object.keys(object[key]).length > 0) && (typeof object[key] != 'string')){ |
| 443 | + container = this._wwwFormUrlEncodeRecurrent(keyWithPrefix, object[key], container); |
| 444 | + } else { |
| 445 | + container.push( |
| 446 | + this._wwwFormUrlEncodePiece(keyWithPrefix) + '=' + |
| 447 | + this._wwwFormUrlEncodePiece(object[key])); |
| 448 | + } |
| 449 | + } |
| 450 | + , this); |
| 451 | + return container; |
| 452 | + }, |
426 | 453 | /** |
427 | 454 | * @param {*} str A key or value to encode as x-www-form-urlencoded. |
428 | 455 | * @return {string} . |
|
433 | 460 | return encodeURIComponent(str.toString().replace(/\r?\n/g, '\r\n')) |
434 | 461 | .replace(/%20/g, '+'); |
435 | 462 | }, |
436 | | - |
437 | 463 | /** |
438 | 464 | * Updates the status code and status text. |
439 | 465 | */ |
|
443 | 469 | } |
444 | 470 | }); |
445 | 471 | </script> |
446 | | - |
|
0 commit comments