Data deconstruction

Keywords: Web Development Attribute

1. Add the two arrays returned from the background (the length of the two arrays is equal) and add the corresponding items in turn.

Business scenarios:

The backstage of the `recharge amount'field has not returned. We need the front end to add the corresponding items of the other returned arrays in turn.

/**
 * @rechargeAmount {Array}
 * Used to process rechargeAmount summation
 * recharge Amount recharge amount = lockRecharge Total locked gold coin recharge amount + unlock Recharge Total unlocked gold coin recharge amount
 *
 */
var rechargeAmount = [];
			for (var i = 0; i < data.dates.length; i++) {
				if (data.lockRechargeTotal[i] === null || data.unlockRechargeTotal[i] === null) {
					data.lockRechargeTotal[i] = 0;
					data.unlockRechargeTotal[i] = 0;
				}
				data.lockRechargeTotal[i] = parseFloat(data.lockRechargeTotal[i]);
				data.unlockRechargeTotal[i] = parseFloat(data.unlockRechargeTotal[i]);
				rechargeAmount[i] = data.unlockRechargeTotal[i] + data.lockRechargeTotal[i];
			}

2. The different arrays returned from the background are transformed into data deconstruction rendered as tables.

< 1 > tablist expected data deconstruction:

Features: campaignInfo is an array returned from the background. We render the list of tables according to this array. It has two characteristics:

<1 -- The length of an array is equal to the number of rows in a table, that is, several pieces of data.

< 2 - Each item of an array is an object, which is a collection of disordered attributes. The number of attributes in each object is equal to the number of columns in the table.

{
	"data":{
		"total":6,
		"campaignInfo":[
			{
				"actionTime":"2018-09-04 09:29:11",
				"adsenseCount":1,
				"campaignStatus":1,
				"campaignTitle":"1",
				"endTime":"2018-11-01 00:00:00",
				"id":25,
				"isPutOn":0,
				"startTime":"2018-10-01 09:29:11"
			},
			{
				"actionTime":"2018-08-01 15:00:38",
				"adsenseCount":0,
				"campaignStatus":2,
				"campaignTitle":"Ji Ji.",
				"endTime":"2018-10-08 00:00:00",
				"id":24,
				"isPutOn":0,
				"startTime":"2018-10-01 00:00:00"
			},
			{
				"actionTime":"2018-08-31 14:14:34",
				"adsenseCount":2,
				"campaignStatus":2,
				"campaignTitle":"test",
				"endTime":"2018-09-15 00:00:00",
				"id":23,
				"isPutOn":0,
				"startTime":"2018-07-31 00:00:00"
			},
			{
				"actionTime":"2018-09-07 00:00:00",
				"adsenseCount":14,
				"campaignStatus":2,
				"campaignTitle":"910 activity",
				"endTime":"2018-09-23 00:00:00",
				"id":22,
				"isPutOn":0,
				"startTime":"2018-09-05 00:00:00"
			},
			{
				"actionTime":"2018-05-20 00:00:00",
				"adsenseCount":0,
				"campaignStatus":2,
				"campaignTitle":"520 activity",
				"endTime":"2018-09-23 00:00:00",
				"id":21,
				"isPutOn":0,
				"startTime":"2018-05-20 00:00:00"
			},
			{
				"actionTime":"2018-04-23 00:00:00",
				"adsenseCount":0,
				"campaignStatus":2,
				"campaignTitle":"423 activity",
				"endTime":"2018-04-23 23:59:59",
				"id":20,
				"isPutOn":0,
				"startTime":"2018-04-23 00:00:00"
			}
		]
	},
	"errorMessage":"",
	"errorCode":""
}

<2> Data deconstruction given us by the background:

{
	"data":{
		"customerNumber":3,
		"customerNumberTotal":86,
		"customers":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,0,0,0],
		"dates":["2018-09-16","2018-09-17","2018-09-18","2018-09-19","2018-09-20","2018-09-21","2018-09-22","2018-09-23","2018-09-24","2018-09-25","2018-09-26","2018-09-27","2018-09-28","2018-09-29","2018-09-30","2018-10-01","2018-10-02","2018-10-03","2018-10-04","2018-10-05","2018-10-06","2018-10-07","2018-10-08","2018-10-09","2018-10-10","2018-10-11","2018-10-12","2018-10-13","2018-10-14","2018-10-15","2018-10-16","2018-10-17"],
		"lockRechargeNumber":"2002.80",
		"lockRechargeTotal":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","6.80","0","0","0","1996.00","0","0","0","0","0"],
		"officialNumber":0,
		"rechargeTimes":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,5,0,0,0,0,0],
		"rechargeTotalPayment":"20994.97",
		"registerCommunityCustomer":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,3,0,2,0,0,0],
		"registerCustomerAmount":["0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.01","0.00","0.10","0.00","398.04","0.00","0.00","0.00"],
		"registerCustomerMonthAmount":["0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","45.00","45.10","0.00","0.00","0.00","0.00","0.00"],
		"registerCustomerMonthTimes":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,0,0,0,0,0],
		"registerCustomerTimes":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,2,0,0,0],
		"registerMemberTotalPayment":"",
		"registerMonthAmount":"90.10",
		"registerMonthNumber":3,
		"registerYearAmount":"398.15",
		"registerYearNumber":4,
		"renewCommunityCustomer":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,1,2,0,0,0],
		"renewCustomerAmount":["0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.10","418.10","0.00","0.00","0.00"],
		"renewCustomerMonthAmount":["0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","45.00","45.10","0.00","0.00","0.00","0.00","0.00"],
		"renewCustomerMonthTimes":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,0,0,0,0,0],
		"renewCustomerTimes":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,0,0,0],
		"renewMonthAmount":"90.10",
		"renewMonthNumber":3,
		"renewTimes":null,
		"renewTimesTotal":0,
		"renewTotalPayment":"",
		"renewYearAmount":"418.20",
		"renewYearNumber":3,
		"renewYears":null,
		"renewYearsTotal":0,
		"timeNumber":6,
		"totalOfficialNumber":0,
		"totalRegisterAmount":48825,
		"totalRegisterCommunityCustomer":7,
		"totalRenewAmount":50830,
		"totalRenewCommunityCustomer":6,
		"trialNumber":0,
		"unlockRechargeNumber":"2994.00",
		"unlockRechargeTotal":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","2994.00","0","0","0","0","0"]
	},
	"errorMessage":"",
	"errorCode":""
}

Processing logic:

Declare an array

Traversing the array, turning every item of the array into an object

----- Add new attributes to the object, corresponding to the tab column

//tablist
		
        var list = [];
		
		for (var i = 0; i < data.dates.length; i++) {
			var k = data.dates.length - i - 1;//Reverse order
			list[k] = {};//Turn every item of an array into an object
			list[k].dates = response.data.data.dates[i];//Object Add Attribute
				                    
            list[k].officialCommunityCustomer=response.data.data.rechargeTimes[i];
			list[k].trialCommunityCustomer = response.data.data.rechargeTimes[i];
				list[k].renewTimes = response.data.data.rechargeTimes[i];
				list[k].renewYears = response.data.data.rechargeTimes[i];
			}

		context.list = list;

 

Posted by JasonTC on Thu, 31 Jan 2019 23:33:15 -0800