블로그 이미지
Xeon의 세상 Xeoness

카테고리

Xeon World (23)
Diary (1)
Tuning (0)
Project (0)
Scrap (0)
Media (0)
L ♡ L (0)
일상생활 (4)
Web Programming (14)
IT 강국? 노가다 강국 (4)
Linux (0)
아리아리 동동~ (0)
Total
Today
Yesterday
뭐가 다른건지 잘 알지 못하겠어서 forum에 가서 뒤적였더니 누군가가 이미 질문을 하고 Animal(유명하군... 저게 진짜 그 사람 얼굴일까??? 중후하게 생긴게 분위기가 숀 코넬린데 ㅋ)님이 답글을 이미 달아놓았다.

renderTo renders the Component into the specified existing element.

==> renderTo는 기존의 element에 component를 rendering 하는 것이다.(즉, 컴퍼넌트 내의 새로운 element를 생성해서 사용할 때 사용한다는 말)

applyTo uses the specified alement as the main element of the Component. A Component created using applyTo does not need rendering - its main element already exists.

==> applyTo는 component의 기본 element에 적용시킬 때 사용.  applyTo를 이용해 생성된 component는 rendering을 필요로 하지 않는다. (기본 element는 component가 생성될 때 이미 만들어지므로)

contentEl is only for Panels. It simply moves the specified element into the body of the Panel when the Panel is rendered to use... as the content!

==> contentEl은 Panel에서만 사용됩니다. Panel이 생성되어진 이후 content와 같은 지정된 element를 Panel의 body로 손쉽게 넣을 수 있습니다.


대충 이런 느낌? ㅋㅋㅋ

'Web Programming > Ext JS' 카테고리의 다른 글

Ext JS - 7. Simple container layout 생성  (0) 2010.01.21
Ext JS - 6. Form 생성  (0) 2010.01.21
Ext JS - 4. Events 등록과 Event Listeners  (0) 2010.01.14
Ext JS - 3. Burst Events in action  (0) 2010.01.14
Ext JS - 2. Dom based Events  (0) 2010.01.14
Posted by Xeoness
, |

Ext-based event가 실행되기 전에 각각의 event가 등록이 되어야 한다. 일반적으로 addEvent method를 이용한다. 아래의 예제를 보자.

var myObservable = new Ext.util.Observable();
myObservable.addEvents('sayHello');
myObservable.addEvents('sayGoodbye');

하나 이상의 event를 등록할 때 아래와 같이 해도 된다.

myObervable.addEvents('sayhello', 'saygoodbye');

Object 형식을 event로 지정할 수도 있다.

myObservable.addEvents({
    'sayHello'        : true,
    'sayGoodbye'  : true
})


event를 생성하였으면 event handler가 필요하다.

myObservable.on('sayHello', function() {
console.log('Hello stranger');
});


sayHello event에 대한 event handler를 생성하였다. 3강에서의 예제처럼 event가 발생하면 firebug의 console 창으로 'Hello stranger' 라는 message를 출력하는 event이다. 아래와 같이 event를 호출해본다.

myObservable.fireEvent('sayHello');


event가 호출되며 Firebug console 창에 'Hello stranger' 라는 message가 호출되는 것을 볼 수 있다.

완성 src :

var myObservable = new Ext.util.Observable();

myObservable.addEvents({
    'sayHello' : true,
    'sayGoodbye' : true
    })
   
myObservable.on('sayHello', function() {
console.log('Hello stranger');
});

myObservable.fireEvent('sayHello');

console 창에 나타난 결과:









대부분의 event들은 파라미터를 사용한다. 'sayGoodbyeFn' event에 2개의 파라미터를 주어보자.

var sayGoodbyeFn = function(firstName, lastName) {
console.log('Goodbye ' + firstName + ' ' + lastName + '!');
}
myObservable.on('sayGoodbye', sayGoodbyeFn);

2개의 파라미터를 인자로 받는 sayGoodbyeFn 이라는 event를 생성하였다.
이제 myObservable.on 함수를 이용하여 event를 호출해 보자. 아래와 같이 추가해 준다.

myObservable.fireEvent('sayGoodbye', 'John', 'Smith');

FireFox에서 실행을 해보자.

console 결과:



 
event를 호출할 때 scope 영역을 지정해 주지 않으면 호출한 component 안에서만 유효하다는 것을 기억해 두자.

event가 더 이상 필요없다면 삭제해 주는 method가 있다.

myObservable.removeListener('sayGoodbye', sayGoodbyeFn);

Posted by Xeoness
, |

부모 노드의 이벤트가 자식 노드에게 상속되길 원하지 않는 경우에는 stopEvent()를 호출하여 정지시켜준다.

아래는 마우스 우클릭 하였을 때, 부모 노드('myDiv')는 브라우저의 메뉴를 보여주지만, 자식 노드('meHref')는 커스텀 메뉴 컨텍스트를 보여주는 예제이다.

파이어 폭스에서 확인을 해보자.(당연한 얘기겠지만, FireBug 설치는 필수이다.)
IE에서 실행하려 하면 script error를 뿜어낼 것인다.(console error)

-------------------------------------------------------------------------------------------------
 // 마우스 우클릭을 하였을 때 실행할 이벤트
Ext.get('myDiv').on('contextmenu', function(eventObj, elRef) { 
    // 콘솔에 글을 뿌려준다.
    console.log('myDiv contextmenu Handler, source elment ID: ' + elRef.id);
    });

// 마우스 우클릭을 하였을 때 실행할 이벤트
Ext.get('myHref').on('contextmenu', function(eventObj, elRef) {
    eventObj.stopEvent();   // 다른 이벤트는 실행하지 않는다.(자신의 이벤트만 실행을 위하여)
    console.log('myHref contextmenu Handler, source elment ID: ' + elRef.id);   // 콘솔에 글을 뿌려준다.

    if (!this.ctxMenu) {                    // ctxMenu 객체가 없다면 새로 생성하는 코드
        this.ctxMenu = new Ext.menu.Menu({  // ctxMenu는 Ext.menu.Menu의 객체
        items : [{                          // item의 내용 (항상 JSON Store 형태로)
        text : "This is"                    // 첫 번째 item text에 'This is'
        },{
        text : "our custom"                 // 두 번째 item text에 'our custom'
        },{
        text : "context menu"               // 세 번째 item text에 'context menu' 를 대입
        }]
        });
    }
   
    this.ctxMenu.show(elRef);               // ctxMenu를 보여준다.
    });
-------------------------------------------------------------------------------------------------

Posted by Xeoness
, |

var el = Ext.get('myDiv');
el.on('click', doSomething);
Ext.get을 이용한 기본적인 방식.

Here, we use the native method, Ext.get, which allows Ext to wrap its element management class, Ext.Element, around a referenced element. Embedded with each instance of Ext.Element is the usage of the Ext event management engine, Ext.util.Observable. It is important to remember that all event management with Ext stems from Ext.util.Observable, which serves as a base for all DOM elements and components that need to manage events.
Next, we attach a listener by calling the el.on and pass the native event to be handled and a method to perform an action on the event. Ext takes event listener registration a step further by allowing you to pass a reference to the scope from which the event handler is to be called and any parameters:

var el = Ext.get('myDiv');
el.on('click', doSomething, scopeRef, [opt1, opt2]);
on 함수에 파라미터 추가

It’s important to note that the default scope is always the object from which the handler is being defined. If scope were not explicitly passed, the method doSomething would be called within the scope of the object el, which is an instantiation of Ext.Element.
Posted by Xeoness
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함