87,964
社区成员
发帖
与我相关
我的任务
分享
var customFieldsJson = [
{
"id": "11",
"name": "F1 ",
"customFieldItems": [
{
"idValue": "5b14d6fc739d8f7582ab59cf",
"idCustomField": "q000001",
},
{
"idValue": "5b14d6fc739d8f7582ab59ca",
"idCustomField": "q000002",
},
{
"value": {
"date": "2018-06-01T03:00:00.000Z"
},
"idCustomField": "q000003",
}
]
},
{
"id": "22",
"name": "F2",
"customFieldItems": [
{
"idValue": "5b14d6fc739d8f7582ab59cf",
"idCustomField": "q000001"
},
{
"idValue": "5b14d6fc739d8f7582ab59ca",
"idCustomField": "q000002"
},
{
"value": {
"date": "2018-06-01T03:00:00.000Z"
},
"idCustomField": "q000003",
}
]
}
];
var customFieldsRows = customFieldsJson.length;
var cards = [];
for(var i = 0; i < customFieldsRows; i++ ){
var id = customFieldsJson[i].id;
var name = customFieldsJson[i].name;
var customFieldItems_0 = customFieldsJson[i].customFieldItems[0].idValue;
var customFieldItems_1 = customFieldsJson[i].customFieldItems[1].idValue;
var customFieldItems_2 = customFieldsJson[i].customFieldItems[2].value.date;
var card = [
id,
name,
customFieldItems_0,
customFieldItems_1,
customFieldItems_2
];
cards.push(card);
}
console.log(cards);
(2) [Array(5), Array(5)]
0: (5) ["11", "F1 ", "5b14d6fc739d8f7582ab59cf", "5b14d6fc739d8f7582ab59ca", "2018-06-01T03:00:00.000Z"]
1: (5) ["22", "F2", "5b14d6fc739d8f7582ab59cf", "5b14d6fc739d8f7582ab59ca", "2018-06-01T03:00:00.000Z"]
var customFieldsJson = [
{
"id": "11",
"name": "F1 ",
"customFieldItems": [
{
"idValue": "5b14d6fc739d8f7582ab59cf",
"idCustomField": "q000001",
},
{
"idValue": "5b14d6fc739d8f7582ab59ca",
"idCustomField": "q000002",
},
{
"value": {
"date": "2018-06-01T03:00:00.000Z"
},
"idCustomField": "q000003",
}
]
},
{
"id": "22",
"name": "F2",
"customFieldItems": [
/*
{
"idValue": "5b14d6fc739d8f7582ab59cf",
"idCustomField": "q000001"
},
*/
{
"idValue": "5b14d6fc739d8f7582ab59ca",
"idCustomField": "q000002"
},
{
"value": {
"date": "2018-06-01T03:00:00.000Z"
},
"idCustomField": "q000003",
}
]
}
];
{
"id": "22",
"name": "F2",
"customFieldItems": [
/*
{
"idValue": "5b14d6fc739d8f7582ab59cf",
"idCustomField": "q000001"
},
*/
{
"idValue": "5b14d6fc739d8f7582ab59ca",
"idCustomField": "q000002"
},
{
"value": {
"date": "2018-06-01T03:00:00.000Z"
},
"idCustomField": "q000003",
}
]
}
var customFieldsJson = [
{
"id": "11",
"name": "F1 ",
"customFieldItems": {
0: {
"idValue": "5b14d6fc739d8f7582ab59cf",
"idCustomField": "q000001",
},
1: {
"idValue": "5b14d6fc739d8f7582ab59ca",
"idCustomField": "q000002",
},
2: {
"value": {
"date": "2018-06-01T03:00:00.000Z"
},
"idCustomField": "q000003",
}
}
},
{
"id": "22",
"name": "F2",
"customFieldItems": {
/*
0: {
"idValue": "5b14d6fc739d8f7582ab59cf",
"idCustomField": "q000001"
},
*/
1: {
"idValue": "5b14d6fc739d8f7582ab59ca",
"idCustomField": "q000002"
},
2: {
"value": {
"date": "2018-06-01T03:00:00.000Z"
},
"idCustomField": "q000003",
}
}
}
];
var customFieldsRows = customFieldsJson.length;
var cards = [];
for(var i = 0; i < customFieldsRows; i++ ){
var id = customFieldsJson[i].id;
var name = customFieldsJson[i].name;
var customFieldItems_0 = "";
var customFieldItems_1 = "";
var customFieldItems_2 = "";
if (customFieldsJson[i].customFieldItems[0])
customFieldItems_0 = customFieldsJson[i].customFieldItems[0].idValue;
if (customFieldsJson[i].customFieldItems[1])
customFieldItems_1 = customFieldsJson[i].customFieldItems[1].idValue;
if (customFieldsJson[i].customFieldItems[2])
customFieldItems_2 = customFieldsJson[i].customFieldItems[2].value.date;
var card = [
id,
name,
customFieldItems_0,
customFieldItems_1,
customFieldItems_2
];
cards.push(card);
}
console.log(cards);
function getItemByField(items, value){
for(var i=0, len=items.length; i<len; ++i){
if(items[i].idCustomField === value){
return items[i];
}
}
}
var customFieldsRows = customFieldsJson.length;
var cards = [];
for(var i = 0; i < customFieldsRows; i++ ){
var id = customFieldsJson[i].id,
name = customFieldsJson[i].name,
customFieldItems_0,
customFieldItems_1,
customFieldItems_2,
item;
// 从customFieldItems找出含'q000001'的记录
item = getItemByField(customFieldsJson[i].customFieldItems, 'q000001');
if(item){
customFieldItems_0 = item.idValue;
}else{
customFieldItems_0 = '';
}
item = getItemByField(customFieldsJson[i].customFieldItems, 'q000002');
customFieldItems_1 = item.idValue;
item = getItemByField(customFieldsJson[i].customFieldItems, 'q000003');
customFieldItems_1 = item.value.date;
var card = [
id,
name,
customFieldItems_0,
customFieldItems_1,
customFieldItems_2
];
cards.push(card);
}
console.log(cards);
(2) [Array(5), Array(5)]
0: (5) ["11", "F1 ", "5b14d6fc739d8f7582ab59cf", "5b14d6fc739d8f7582ab59ca", "2018-06-01T03:00:00.000Z"]
1: (5) ["22", "F2", "", "5b14d6fc739d8f7582ab59ca", "2018-06-01T03:00:00.000Z"]
var customFieldsJson = [
{
"id": "11",
"name": "F1 ",
"customFieldItems": [
{
"idValue": "5b14d6fc739d8f7582ab59cf",
"idCustomField": "q000001",
},
{
"idValue": "5b14d6fc739d8f7582ab59ca",
"idCustomField": "q000002",
},
{
"value": {
"date": "2018-06-01T03:00:00.000Z"
},
"idCustomField": "q000003",
}
]
},
{
"id": "22",
"name": "F2",
"customFieldItems": [
/*
{
"idValue": "5b14d6fc739d8f7582ab59cf",
"idCustomField": "q000001"
},
*/
{
"idValue": "5b14d6fc739d8f7582ab59ca",
"idCustomField": "q000002"
},
{
"value": {
"date": "2018-06-01T03:00:00.000Z"
},
"idCustomField": "q000003",
}
]
}
];
var customFieldsRows = customFieldsJson.length;
var cards = [];
for(var i = 0; i < customFieldsRows; i++ ){
var id = customFieldsJson[i].id;
var name = customFieldsJson[i].name;
var customFieldItems_0 = customFieldsJson[i].customFieldItems[0].idValue;
var customFieldItems_1 = customFieldsJson[i].customFieldItems[1].idValue;
var customFieldItems_2 = customFieldsJson[i].customFieldItems[2].value.date;
var card = [
id,
name,
customFieldItems_0,
customFieldItems_1,
customFieldItems_2
];
cards.push(card);
}
console.log(cards);