더북(TheBook)

다음은 몽고DB 컬렉션 AddressBookinsert 메서드를 address에 등록하는 과정을 구현한 코드다.

~/Projects/addressBook/client/addressList.js

생략
Template.addressInput.events({
    ‘click button[name=saveAddress]’ (evt,tmpl){
        /* input 박스 값으로 입력 데이터 만들기 /
        var address = {
        생략
        };
        / insert 하기 /
        AddressBook.insert(address);
        / input 값 초기화하기 /
    }
});

그리고 input 박스를 초기화한다.

~/Projects/addressBook/client/addressList.js

생략
Template.addressInput.events({
    ‘click button[name=saveAddress]’ (evt,tmpl){
        / input 박스 값으로 입력 데이터 만들기 /
        생략
        / insert 하기 */
        생략

    <span class="cm">/* input 값 초기화하기 */</span>
   <span class="cd2"> <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=name]"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span></span>
  <span class="cd2">  <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=phone]"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span></span>
  <span class="cd2">  <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"inp ut[name=email]"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span></span>
   <span class="cd2"> <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=company]"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span></span>
   <span class="cd2"> <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=birthday]"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
<span class="p">}</span></span>

});

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.