pagekit / vue-resource

The HTTP client for Vue.js
MIT License
10.09k stars 1.6k forks source link

serialize array object must be PlainObject? #706

Open Grart opened 5 years ago

Grart commented 5 years ago

serialize array object must be PlainObject?that is why?

demo 1: ` class Info { FieldName: string = null; Desc: boolean = false; }

  const _info = new Info();
  _info.FieldName = "abc";
  _info.Desc = true;

  let _obj = {
    qModel: { SortInfoArray: [_info] }
  };

` form data: qModel[SortInfoArray][0][]: abc qModel[SortInfoArray][0][]: true

demo 2: let _obj ={ qModel: { SortInfoArray: [{ FieldName: "abc", Desc: true }] } }; form data: qModel[SortInfoArray][0][FieldName]: abc qModel[SortInfoArray][0][Desc]: true

sorce code `

    function serialize(params, obj, scope) {

    var array = isArray(obj), plain = isPlainObject(obj), hash;

    each(obj, function (value, key) {

    hash = isObject(value) || isArray(value);

    if (scope) {
        key = scope + '[' + (plain || hash ? key : '') + ']';
    }

    if (!scope && array) {
        params.add(value.name, value.value);
    } else if (hash) {
        serialize(params, value, key);
    } else {
        params.add(key, value);
    }
});

} `

bloor commented 3 years ago

I have same issue. It seems the plugin removes / stops whenever it reaches "{". The jQuery alternative does not do that.