ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • json데이터 반복문으로 로컬스토리지에 저장하는 로직
    Javascript/javascript기록 2021. 4. 16. 10:28
    728x90
    function Anal_Person_Save() {
    	 
    			//왜 웹스토리지로 하냐면 우선 서버의 부하를 줄이고, com계정마다 컴퓨터마다 설정값이 다를 수 있기 때문에.
    			var data = new Object();
    			var Name_Array = [
    				"EMP_NO","KOREAN_NAME","CHINESE_NAME","ENGLISH_NAME","CODE_GRADE","CODE_LEVEL","DUTY_CODE","RESIDENT_NO","MARRY_TAG","ENTER_DATE","UNION_ENTER_DATE","CODE_SCHOOL","CODE_RELIGION","TEL","BIRTHDAY","CURRENT_ADDR",
    				"HAND_PHONE","E_MAIL","HOBBY","TALENT","YEAR_AMT","TIME_AMT","MONTH_AMT","CODE_PAYGUBN","RETIRE_DATE","CODE_APPOINT","G_ENTER_DATE","bRETIRE_DATE","TASK","CODE_DUTY_GROUP","COMPNAME","CODE_ENTER"
    			];
    
    			for(var i=0; i<Name_Array.length; i++){
    				
    				var Name_val = (j$("input[name='" + Name_Array[i] +"']").is(":checked")) ? j$("input[name='" + Name_Array[i] +"']").val() : "";
    				data[Name_Array[i]] = Name_val;
    				//data = {
    				//	[Name_key]:123
    				//};
    				//data.EMP_NO = 123;
    				//data.KOREAN_NAME = 123;
    
    			}
    			
    			localStorage.setItem('object', JSON.stringify( data ));
    			var test =JSON.parse(localStorage.getItem('object'));
    			
    			location.reload(); //새로고침으로 formLoad함수를 다시 실행시킴
    	}
    
    	function getSettingStorage(){
    			
    		var Person_Anal_obj = JSON.parse(localStorage.getItem('object')); 
    		
    		if(!Person_Anal_obj) return false; //최초 설정 저장이 없을경우
    
    		
    		for (var key in Person_Anal_obj) {
    
    			if(Person_Anal_obj[key] ==="1"){
    				j$("input[name='"+key+"']").prop("checked", true);
    			}else{
    				j$("input[name='"+key+"']").prop("checked", false);
    			}
    			
    		}			
    	}

    jquery필수 

    728x90
Designed by Tistory.