javascript - How to convert data into key-value pairs in an array? ? js
世界只因有你
世界只因有你 2017-05-19 10:09:07
0
2
461


How to take out the data of Plan_ADEP and Plan_ADES in the picture and convert it into the data format shown in the picture above? ?

世界只因有你
世界只因有你

reply all(2)
小葫芦
var contents = what.contents, //先获取数据
    tempArr = [];
 
for( var i = 0,content; content = contents[i++]; ){
    var arr = [];
    for( var key in content ){
        var obj_1 = {},
            obj_2 = {};
        if(key == "Plan_ADEP"){
            obj_1[key] = content[key];
            arr.push(obj_1);
        }
        if(key == "Plan_ADES"){
            obj_2[key] = content[key];
            arr.push(obj_2);
        }
    }
    tempArr.push(arr);
    //tempArr就是你要的值
}   

//或者这样写更简单:
/*
for( var i = 0,content; content = contents[i++]; ){
    var arr = [],obj_1 = {},obj_2 = {};
    obj_1.Plan_ADEP = content.Plan_ADEP;
    obj_2.Plan_ADES = content.Plan_ADES;
    arr.push(obj_1);
    arr.push(obj_2);
    tempArr.push(arr);
    //tempArr就是你要的值
}
*/
 

I don’t know if I understood you wrong

为情所困
var GZData=[];
contents.map(function(item){
    GZData.push([{name:"广州"},{name:item.Plan_ADEP,value:item.Plan_ACID_Three}]);
})
console.log(GZData)

Note: contents. is the contents array in the data of your picture. You take it out; then GZData is the format you want. I don’t know.
{name: "Guangzhou"}, {name: item.Plan_ADEP, value: item.Plan_ACID_Three} Which one you want to target, you can use item to correspond

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template