如何将我的所有数据转换为对象?例:
//From
var a = Immutable.fromJS({ formats: ["foo", "bar"]})
a.toObject()
// How returns { formats: ["foo", "bar"] }
// How i need { formats: {0: "foo", 1: "bar"}}
由于
答案 0 :(得分:1)
根据这里给出的答案:Convert Array to Object
var a = Immutable.fromJS({ formats: ["foo", "bar"]});
var b = {formats: toObject(a.get('formats').toJSON())};
console.log(b);
function toObject(arr) {
var rv = {};
for (var i = 0; i < arr.length; ++i)
if (arr[i] !== undefined) rv[i] = arr[i];
return rv;
}