Through: data statistics methods, jQuery, urgent online, etc. A group of data is obtained through the console. log, the output format is as follows] [2] {code ...} question: How can I use jquery to parse this data structure and output the content at a specified position... try: I try to add [...
Through: data statistics methods, jQuery, urgent online, etc.
A group of data is obtained. After console. log, the output format is as follows:
] [2]
// The final data structure is // {// 'product key1': {// prod: 'product name1', // event: {// 'event type key1 ': {type: 'event type 1', count: event quantity}, // 'event type key2': {type: 'event type 2', count: event quantity} //}, // 'product key2': {// prod: 'product name2', // event: {// 'event type key3 ': {type: 'event type 3', count: event quantity}, // 'event type key4': {type: 'event type 4', count: event count }//}//},//... //}
Problem:
How can I use jquery to parse this data structure and output the content at a specified position...
Try:
I tried to add [''] After the result-although I knew it was definitely wrong, I tried it again. Yes, it was really wrong.
JSON. parse (result) is used. The output result also reports an error...
Solution
Reply content:
Through: data statistics methods, jQuery, urgent online, etc.
A group of data is obtained. After console. log, the output format is as follows:
] [2]
// The final data structure is // {// 'product key1': {// prod: 'product name1', // event: {// 'event type key1 ': {type: 'event type 1', count: event quantity}, // 'event type key2': {type: 'event type 2', count: event quantity} //}, // 'product key2': {// prod: 'product name2', // event: {// 'event type key3 ': {type: 'event type 3', count: event quantity}, // 'event type key4': {type: 'event type 4', count: event count }//}//},//... //}
Problem:
How can I use jquery to parse this data structure and output the content at a specified position...
Try:
I tried to add [''] After the result-although I knew it was definitely wrong, I tried it again. Yes, it was really wrong.
JSON. parse (result) is used. The output result also reports an error...
Solution
If you want your data to be like this
// [// Prod: 'product name1', // event: [// {type: 'event type 1', count: event quantity}, // {type: 'event type 2', count: event quantity} //] //}, // {// prod: 'product name 2', // event: [// {type: 'event type 3', count: event quantity}, // {type: 'event type 4', count: event quantity} //] //} //]
Then convert the data structure of the original result:
var result2=[];for(var key in result){ if(result.hasOwnProperty(key)){ result2.push(result[key]); }}result2.forEach(function(item,index){ var events=[]; for(var eventKey in item['event']){ if(item['event'].hasOwnProperty(eventKey)){ events.push(item['event'][eventKey]); } } item.events=events;});console.log(result2);
Q: Who wrote the previous data structure? Fan him ......
Do you want to bind an event to the row of the corresponding product Id on the page?