Function qsStringify

  • 对象转 queryString 暂时只支持两层数据,第二层对象与与数组值不能为引用类型。

    Parameters

    • obj: any

      源数据

    • Optionaloptions: {
          arr2str?: boolean;
          hasBrackets?: boolean;
          hasIndex?: boolean;
          urlEncode?: boolean;
      }
      • Optionalarr2str?: boolean
      • OptionalhasBrackets?: boolean
      • OptionalhasIndex?: boolean
      • OptionalurlEncode?: boolean

    Returns string

    qsStringify({ start: 0, count: 20, obj: { a: 1 }, arr: [1, 2, 3] }); /// 'start=0&count=20&obj[a]=1&arr[]=1&arr[]=2&arr[]=3'
    qsStringify({ start: 0, count: 20, obj: { a: 1 }, arr: [1, 2, 3] }, { arr2str: true }); /// 'start=0&count=20&obj[a]=1&arr=1,2,3'
    qsStringify({ start: 0, count: 20, obj: { a: 1 }, arr: [1, 2, 3], str: '1' }, { hasIndex: true }); /// 'start=0&count=20&obj[a]=1&arr[0]=1&arr[1]=2&arr[2]=3&str=1'