{
  "id": "ROOT",
  "quantity": {
    "value": 1,
    "unit": "EA"
  },
  "productId": "ALP_DEMO_202105",
  "priceLineAssignments": [],
  "variableAssignments": [
    {
      "value": "2021-05-11T12:00:00Z",
      "variableId": "DIM_BUILDDATE"
    },
    {
      "value": "ALP_DEMO_202105_START",
      "variableId": "EVENT"
    }
  ],
  "arguments": {},
  "sublines": []
}


    /**
     * 数组中随机取几个元素
     * arr      数组
     * count    要取的数量
     */
function getRandomArrayElements(arr, count) {
    var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
    while (i-- > min) {
        index = Math.floor((i + 1) * Math.random());
        temp = shuffled[index];
        shuffled[index] = shuffled[i];
        shuffled[i] = temp;
    }
    return shuffled.slice(min);
}


var items = ['i1','i2','i4','i5','i3','i7','8','9','10'];
console.log( getRandomArrayElements(items, 1)[0] );

var OUTPUT_01_VAL_V = "ACTUAL_CAR_CEILING_H";
 $('.configit').each(function () {
	if ($(this).attr("data-configit") == OUTPUT_01_VAL_V) {
		//ACTUAL_CAR_CEILING_H
		//ACUTAL_DIM_COP_CABLE
		//SAP_CAR_TYPE
		OUTPUT_01_VAL_V = $(this).val();
		console.log("==>"+OUTPUT_01_VAL_V);
		return false;
	}
});
console.log(OUTPUT_01_VAL_V);


var variableAssignments = [];
var varData = {
        "value": "VERSION_ST_DATE",
        "variableId": "EVENT"
    };
    variableAssignments.push(varData);

    varData = {
        "value": "2021-04-11T12:00:00Z",
        "variableId": "DIM_BUILDDATE"
    };
    variableAssignments.push(varData);
	
	console.log("variableAssignments1=>" + JSON.stringify(variableAssignments));
	
	var replacement = {
            "value": "",
            "variableId": "DIM_BUILDDATE"
        };
		
		var existFlag = false;
		for (let i = 0; i < variableAssignments.length; i++) {
            if (variableAssignments[i].variableId === replacement.variableId) {

                if (replacement.value == "") { 
                    variableAssignments.splice(i);
                } else {
                    variableAssignments[i] = replacement;
                }
                
                existFlag = true;
            }
        }

        if (!existFlag) variableAssignments.push(replacement);
        console.log("variableAssignments2=>" + JSON.stringify(variableAssignments));
						

  

posted on 2021-05-24 10:01  站在那看风景  阅读(59)  评论(0编辑  收藏  举报