더북(TheBook)

~/Projects/addressBook/client/addressList.js

Template.addressList.helpers({

    <span class="k">return</span> <span class="nx">AddressBook</span><span class="p">.</span><span class="nx">find</span><span class="p">({},{</span><span class="nx">limit</span><span class="o">:</span><span class="mi">10</span> <span class="p">,</span><span class="nx">sort</span><span class="o">:</span><span class="p">{</span><span class="nx">name</span><span class="o">:</span><span class="mi">1</span><span class="p">}});</span>
<span class="p">}</span>

});

Template.addressList.events({ ‘click button[name=remove]’ (evt,tmpl){ AddressBook.remove( { _id : this._id } ); } });

Template.addressInput.events({ ‘click button[name=saveAddress]’ (evt,tmpl){

    <span class="cm">/* input 박스 값으로 입력 데이터 만들기 */</span>
    <span class="kd">var</span> <span class="nx">address</span> <span class="o">=</span> <span class="p">{</span>
        <span class="nx">name</span>    <span class="o">:</span> <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="p">,</span><span class="nx">phone</span>   <span class="o">:</span> <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="p">,</span><span class="nx">email</span>   <span class="o">:</span> <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=email]"</span><span class="p">).</span><span class="nx">value</span>
        <span class="p">,</span><span class="nx">company</span> <span class="o">:</span> <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="p">,</span><span class="nx">birthday</span>    <span class="o">:</span> <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="p">};</span>

    <span class="cm">/* Insert 하기 */</span>
    <span class="nx">AddressBook</span><span class="p">.</span><span class="nx">insert</span><span class="p">(</span><span class="nx">address</span><span class="p">);</span>

    <span class="cm">/* input 값 초기화하기 */</span>
    <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 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 class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[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 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 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>

});

~/Projects/addressBook/client/main.html

<head>

    <title>Address Book</title>

</head>

<body>

    {{> addressInput}} <!– 입력 템플릿 추가 –>

    {{> addressList}} <!– 리스트 템플릿 추가 –>

</body>


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