第一个[{title:'主题'; date: '2016-10-16 07:49'; depart: '发月始条的近利'; file: '通儿角'; },{title:'主题2'; date: '2016-10-16 07:49'; depart: '发月始条的近利2'; file: '通儿角2'; }] 第二个:[ { name: '文件文号', fieldName: 'file' }, { name: '部门', fieldName: 'depart' }, { name: '日期', fieldName: 'date' } ] 第三个[ {title:'主题',tplConfig:[{ name: '文件文号', file: '通儿角' }, { name: '部门', depart: '发月始条的近利' }, { name: '日期', date: '2016-10-16 07:49' }]}, {title:'主题2',tplConfig:[{ name: '文件文号', file: '通儿角2' }, { name: '部门', depart: '发月始条的近利2' }, { name: '日期', date: '2016-10-16 07:49' }]} ] 把第一个和第二个数据处理成第三组数据,用jquery语法
时间: 2023-08-15 17:03:48 浏览: 80
可以使用 jQuery 的 map() 和 each() 方法来实现数据处理。代码示例如下:
```
var data1 = [{title:'主题', date: '2016-10-16 07:49', depart: '发月始条的近利', file: '通儿角'}, {title:'主题2', date: '2016-10-16 07:49', depart: '发月始条的近利2', file: '通儿角2'}];
var data2 = [{ name: '文件文号', fieldName: 'file' }, { name: '部门', fieldName: 'depart' }, { name: '日期', fieldName: 'date' }];
var data3 = [];
// 处理第三组数据
$.each(data1, function(index, item) {
var tplConfig = [];
$.map(data2, function(field) {
tplConfig.push({ name: field.name, [field.fieldName]: item[field.fieldName] });
});
data3.push({title: item.title, tplConfig: tplConfig});
});
// 打印结果
console.log(data3);
```
执行结果如下:
```
[
{
"title": "主题",
"tplConfig": [
{
"name": "文件文号",
"file": "通儿角"
},
{
"name": "部门",
"depart": "发月始条的近利"
},
{
"name": "日期",
"date": "2016-10-16 07:49"
}
]
},
{
"title": "主题2",
"tplConfig": [
{
"name": "文件文号",
"file": "通儿角2"
},
{
"name": "部门",
"depart": "发月始条的近利2"
},
{
"name": "日期",
"date": "2016-10-16 07:49"
}
]
}
]
```
阅读全文