참고 : http://www.json.org/js.html
Json Parser 다운 : https://github.com/douglascrockford/JSON-js

// json text -> object
var objText = '{"name":"뚱2"}';
var obj = JSON.parse(objText);

// json Object -> text
var newText = JSON.stringify(obj);

2012-02-06 추가
json text 는 꼭 key와 value를 쌍따옴표로 감싸야 한다.
그렇지 않는다면 JSON.parse를 사용했을때 정상적으로 파싱되지 않는다.
예)
// Object
JSON.parse('{"name":"뚱2"}');
// Not Object
JSON.parse("{'name':'뚱2'}");


참고 : http://itzone.tistory.com/169
posted by 뚱2



// 추가
$("< OPTION >< /OPTION >")
	.attr("selected", "selected")
	.text("추가")
	.attr("value", "추가")
	.appendTo("select[name='test']");

// 선택
var value = $("select[name='test'] option:selected").val();
var name = $("select[name='test'] option:selected").text();

// 특정 삭제
$("select[name='test'] option[value='추가']").remove();
// 선택 삭제
$("select[name='test'] option:selected").remove();
// 모두 삭제
$("select[name='test'] option").remove();




posted by 뚱2
거창한건 아닙니다. 그냥 간단한 Tip입니다.
json으로 비동기 통신을 하다보면은 결과 값을 json Text로 받는 경우가 있습니다.


이걸 Javascript Object 로 변경주어야 스크립트 단에서 사용 할 수 있습니다.

    // 승인
	$("#btn_approval").click(function() {
		var selRows = $(DF.ID.GRID_MAIN).getGridParam("selarrrow");
		if ( selRows.length == 0) {
			alert("항목을 선택해 주세요.");
			return;
		}
			
		$.ajax({
		     type: 'POST'
		    ,url : DF.URL.APPROVAL
		    ,data: {id : selRows}
			,success: function(data) {
				var ret = eval("(" + data + ")");
				if (ret.success == "true") {
					alert(ret.message);
					$(DF.ID.GRID_MAIN).trigger("reloadGrid");
				}

		    }
			,error: function(result) {
		    }
		});		
	});

14번째의 줄 같이 넘어온 값을 "()"로 묶어서 eval함수를 실행해 주시면 됩니다.

* 추가 2012-02-07
eval을 사용하는건 보안상 위험이 있습니다. JSON.parse ( http://www.json.org/ ) 사용하는걸 권장합니다.




'JavaScript > Json' 카테고리의 다른 글

[JSON] douglascrockford json2.js download  (0) 2013.11.25
[JSON] JSON  (0) 2012.10.30
[Json] Json Text <-> Json Object 변환  (0) 2011.11.01
posted by 뚱2

[jQuery] serialize()

JavaScript/jQuery 2011. 10. 17. 18:13
참고 : http://api.jquery.com/serialize/

폼객체의 엘리먼트들을 데이터 인코딩까지 해서 연결해주는 기능이다.
편한기능
posted by 뚱2
출처 : http://jqfundamentals.com/book/index.html#chapter-1
var myFunction = function() {
    console.log('hello');
};

var myObject = {
    foo : 'bar'
};

var myArray = [ 'a', 'b', 'c' ];

var myString = 'hello';

var myNumber = 3;

typeof myFunction;   // returns 'function'
typeof myObject;     // returns 'object'
typeof myArray;      // returns 'object' -- careful!
typeof myString;     // returns 'string';
typeof myNumber;     // returns 'number'

typeof null;         // returns 'object' -- careful!


if (myArray.push && myArray.slice && myArray.join) {
    // probably an array
    // (this is called "duck typing")
}

if (Object.prototype.toString.call(myArray) === '[object Array]') {
    // Definitely an array!
    // This is widely considered as the most robust way
    // to determine if a specific value is an Array.
}



posted by 뚱2

기존은 Ext.util.JSON이었는데 4.0으로 오면서 Ext.JSON으로 변경되었다.

이거때문에 한참을 삽질 했네 ㅡㅡ;

'JavaScript > ExtJS' 카테고리의 다른 글

[ExtJS] ExtJs Grid 즐겨찾기  (0) 2012.02.09
posted by 뚱2

'JavaScript > Html' 카테고리의 다른 글

[html] Zen Coding 링크  (0) 2012.09.23
[html] dd, dt, dl  (0) 2012.06.22
[html] http 프로토콜  (0) 2012.02.16
[html] map 사용  (0) 2011.07.22
posted by 뚱2
오브젝트브 C에 대한 .js 파일이 없기에 기존 shBrushCpp.js 파일을 이용해서 shBrushObjc.js 파일을 만들었습니다.

크게 바뀐건 없고 간단한 파일 @ 키워드와 [] 대괄호 부분을 하이라이트 했습니다.

알리아스 명은 objc, Objc 두개 사용가능 합니다.

제가 잘 사용하고 있는 기존 2.0.296 버전을 수정했습니다.

키워드 중 'CA\\w+ CF\\w+ NS\\w+ UI\\w+' 은 인터넷이서 찾다가 다른분걸 배꼈는데 어디서 찾았는지

기억이 나지않네요.

찾는데로 출처를 적겠습니다.




syntaxhighlighter_2.0.296_20110801.zip


 
posted by 뚱2

[html] map 사용

JavaScript/Html 2011. 7. 22. 13:51
이미지의 전체를 링크거는게 아닌 일정 부분에 링크걸때 유용한 태그

 


	1
	2
	3
	4

'JavaScript > Html' 카테고리의 다른 글

[html] Zen Coding 링크  (0) 2012.09.23
[html] dd, dt, dl  (0) 2012.06.22
[html] http 프로토콜  (0) 2012.02.16
[html] html 특수문자 태그  (0) 2011.08.18
posted by 뚱2
* Javascript this에 관한 글
http://blog.mixed.kr/94


posted by 뚱2

[javascript] Closures

JavaScript/JavaScript 2011. 5. 24. 23:05
요즘 회사일로 웹프로그래밍을 하고 있습니다.
개발을 진행하다보니까 서버쪽은 정형화 되어 있어서 그나마 편하게 진행하는데
이놈은 자바스크립트가 발목을 잡네요.

그간 건성으로 form validation에만 사용하거나 약간의 UI를 컨트롤 할때 사용하던 자바스크립트.
자바스크립트로도 객체를 만들수 있고(?) 상속도 할수있다는 사실에 얼마나 놀랐던지

그중 지금도 이해가 다 되지 않고 난해한 Closures에 대한 좋은 글이 있어서 링크 걸어둡니다.

클로저를 처음 발견(?) 한 사람 더글라스 크록포드 글
http://crockford.com/javascript/private.html

낭만백수님 번역
http://mulriver.egloos.com/4666528  

클로저에 대한 소개글
http://sirini.net/blog/?p=1052

인터넷 익스플로러에서 메모리 릭
http://msdn.microsoft.com/en-us/library/Bb250448.aspx


ps. 이자릴 빌려 번역해주신 낭만백수님께 정말로 감사드립니다. 
posted by 뚱2
* Javascript Source
         
        

* html form Source
        

자바스크립트 소스의 13번 줄에 oChildNodes(i).tagName이 있는데 iE에서는 oChildNodes(i).getAttribute("tagName")으로도 호출이 되지만
크롬에서는 null을 리턴합니다.
결국 크로스브라우징을 위해서는 property 이름 그대로 사용하고 사용자 attribute만 getAttribute, setAttribute를 사용해야겠습니다.

PS. FireFox나 Safari에서는 테스트를 못했습니다. 
posted by 뚱2
여러 버전 사용해 보고 나에게 제일 맞는 버전이라 생각이 든다.

내 블로그 적용한 이미지


 
posted by 뚱2