且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将JSON对象转换为另一个对象-对其进行格式化

更新时间:2023-01-08 11:49:36

您可以遍历所有项目并将其推入新对象:

You could just loop through the items and push them into a new object:

var len = old.data.length,
    newData = {aaData:[]},
    i;

for ( i=0; i < len; i+=1 ) {
    newData.aaData.push( [ old.data[ i ].id, old.data[ i ].name] );   
}

示例: https://jsfiddle.net/q2Jzb/1/

您大概会将它们传递给DataTables(使用名称aaData),请注意,DataTables 将对象作为配置,它与JSON不同.

You are presumably passing these to DataTables (as you use the name aaData), note that DataTables takes an object as the configuration, it's not the same as JSON.